effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
Prims.Tot
val is_uvar (t: term) (uvs: env) : option var
[ { "abbrev": true, "full_module": "Pulse.Checker.Prover.Substs", "short_module": "PS" }, { "abbrev": true, "full_module": "Pulse.Syntax.Printer", "short_module": "P" }, { "abbrev": true, "full_module": "Pulse.Reflection.Util", "short_module": "RUtil" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2.TermEq", "short_module": "TermEq" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let is_uvar (t:term) (uvs:env) : option var = match t.t with | Tm_FStar t -> refl_uvar t uvs | _ -> None
val is_uvar (t: term) (uvs: env) : option var let is_uvar (t: term) (uvs: env) : option var =
false
null
false
match t.t with | Tm_FStar t -> refl_uvar t uvs | _ -> None
{ "checked_file": "Pulse.Checker.Prover.Match.fst.checked", "dependencies": [ "Pulse.Typing.Util.fsti.checked", "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.Printer.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Prover.Util.fsti.checked", "Pulse.Checker.Prover.Substs.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.TermEq.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.Match.fst" }
[ "total" ]
[ "Pulse.Syntax.Base.term", "Pulse.Typing.Env.env", "Pulse.Syntax.Base.__proj__Mkterm__item__t", "Pulse.Syntax.Base.host_term", "Pulse.Checker.Prover.Match.refl_uvar", "Pulse.Syntax.Base.term'", "FStar.Pervasives.Native.None", "Pulse.Syntax.Base.var", "FStar.Pervasives.Native.option" ]
[]
module Pulse.Checker.Prover.Match open Pulse.Syntax open Pulse.Typing open Pulse.Typing.Combinators open Pulse.Typing.Metatheory open Pulse.Typing.Util open Pulse.Checker.VPropEquiv open Pulse.Checker.Prover.Base open Pulse.Checker.Prover.Util module L = FStar.List.Tot module R = FStar.Reflection.V2 module TermEq = FStar.Reflection.V2.TermEq module T = FStar.Tactics.V2 module RUtil = Pulse.Reflection.Util module P = Pulse.Syntax.Printer module PS = Pulse.Checker.Prover.Substs let equational (t:term) : bool = match t.t with | Tm_FStar host_term -> (match R.inspect_ln host_term with | R.Tv_Match _ _ _ -> true | _ -> false) | _ -> false let type_of_fv (g:env) (fv:R.fv) : T.Tac (option R.term) = let n = R.inspect_fv fv in match R.lookup_typ (fstar_env g) n with | None -> None | Some se -> match R.inspect_sigelt se with | R.Unk -> None | R.Sg_Let _ lbs -> ( L.tryPick (fun lb -> let lbv = R.inspect_lb lb in if R.inspect_fv lbv.lb_fv = n then Some lbv.lb_typ else None) lbs ) | R.Sg_Val _ _ t -> Some t | R.Sg_Inductive _nm _univs params typ _ -> None let is_smt_fallback (t:R.term) : bool = match R.inspect_ln t with | R.Tv_FVar fv -> let name = R.inspect_fv fv in name = ["Steel";"Effect";"Common";"smt_fallback"] | _ -> false (* When comparing t0 =?= t1, if they are not syntactically equal, we have to decide whether or not we should fire an SMT query to compare them for provable equality. The criterion is as follows: 1. We allow an SMT query if either t0 or t1 is "equational". For now, that means that either is a match expression. 2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un` of the same head symbol `f`, a top-level constant, then we check if the type of `f` decorates any of its binders with the `smt_fallback` attribute. - If none of them are marked as such, then we check if `f v0...` is syntactically equal to `f u0...` and allow an SMT query to check if vn = vm. That is, the default behavior for predicates is that they *last* argument is eligible for SMT equality. - Otherwise, for each binder that is NOT marked as `smt_fallback`, we check if the corresponding argument is syntactically equal. If so, we allow t0 and t1 to be compared for SMT equality. For example, Steel.ST.Reference.pts_to is defined like so: /// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)] /// is unifiable with [pts_to r p (1 + v)] val pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop *) let eligible_for_smt_equality (g:env) (t0 t1:term) : T.Tac bool = let either_equational () = equational t0 || equational t1 in let head_eq (t0 t1:R.term) = match R.inspect_ln t0, R.inspect_ln t1 with | R.Tv_App h0 _, R.Tv_App h1 _ -> TermEq.term_eq h0 h1 | _ -> false in match t0.t, t1.t with | Tm_FStar t0, Tm_FStar t1 -> ( let h0, args0 = R.collect_app_ln t0 in let h1, args1 = R.collect_app_ln t1 in if TermEq.term_eq h0 h1 && L.length args0 = L.length args1 then ( match R.inspect_ln h0 with | R.Tv_FVar fv | R.Tv_UInst fv _ -> ( match type_of_fv g fv with | None -> either_equational() | Some t -> let bs, _ = R.collect_arr_ln_bs t in let is_smt_fallback (b:R.binder) = let bview = R.inspect_binder b in L.existsb is_smt_fallback bview.attrs in let some_fallbacks, fallbacks = L.fold_right (fun b (some_fallbacks, bs) -> if is_smt_fallback b then true, true::bs else some_fallbacks, false::bs) bs (false, []) in if not some_fallbacks then ( //if none of the binders are marked fallback //then, by default, consider only the last argument as //fallback head_eq t0 t1 ) else ( let rec aux args0 args1 fallbacks = match args0, args1, fallbacks with | (a0, _)::args0, (a1, _)::args1, b::fallbacks -> if b then aux args0 args1 fallbacks else if not (TermEq.term_eq a0 a1) then false else aux args0 args1 fallbacks | [], [], [] -> true | _ -> either_equational() //unequal lengths in aux args0 args1 fallbacks ) ) | _ -> either_equational () ) else either_equational () ) | _ -> either_equational () let refl_uvar (t:R.term) (uvs:env) : option var = let open R in match inspect_ln t with | Tv_Var v -> let {uniq=n} = inspect_namedv v in if contains uvs n then Some n else None | _ -> None
false
true
Pulse.Checker.Prover.Match.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val is_uvar (t: term) (uvs: env) : option var
[]
Pulse.Checker.Prover.Match.is_uvar
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: Pulse.Syntax.Base.term -> uvs: Pulse.Typing.Env.env -> FStar.Pervasives.Native.option Pulse.Syntax.Base.var
{ "end_col": 13, "end_line": 163, "start_col": 2, "start_line": 161 }
Prims.Tot
val is_smt_fallback (t: R.term) : bool
[ { "abbrev": true, "full_module": "Pulse.Checker.Prover.Substs", "short_module": "PS" }, { "abbrev": true, "full_module": "Pulse.Syntax.Printer", "short_module": "P" }, { "abbrev": true, "full_module": "Pulse.Reflection.Util", "short_module": "RUtil" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2.TermEq", "short_module": "TermEq" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let is_smt_fallback (t:R.term) : bool = match R.inspect_ln t with | R.Tv_FVar fv -> let name = R.inspect_fv fv in name = ["Steel";"Effect";"Common";"smt_fallback"] | _ -> false
val is_smt_fallback (t: R.term) : bool let is_smt_fallback (t: R.term) : bool =
false
null
false
match R.inspect_ln t with | R.Tv_FVar fv -> let name = R.inspect_fv fv in name = ["Steel"; "Effect"; "Common"; "smt_fallback"] | _ -> false
{ "checked_file": "Pulse.Checker.Prover.Match.fst.checked", "dependencies": [ "Pulse.Typing.Util.fsti.checked", "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.Printer.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Prover.Util.fsti.checked", "Pulse.Checker.Prover.Substs.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.TermEq.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.Match.fst" }
[ "total" ]
[ "FStar.Reflection.Types.term", "FStar.Reflection.V2.Builtins.inspect_ln", "FStar.Reflection.Types.fv", "Prims.op_Equality", "Prims.list", "Prims.string", "Prims.Cons", "Prims.Nil", "FStar.Reflection.Types.name", "FStar.Reflection.V2.Builtins.inspect_fv", "FStar.Reflection.V2.Data.term_view", "Prims.bool" ]
[]
module Pulse.Checker.Prover.Match open Pulse.Syntax open Pulse.Typing open Pulse.Typing.Combinators open Pulse.Typing.Metatheory open Pulse.Typing.Util open Pulse.Checker.VPropEquiv open Pulse.Checker.Prover.Base open Pulse.Checker.Prover.Util module L = FStar.List.Tot module R = FStar.Reflection.V2 module TermEq = FStar.Reflection.V2.TermEq module T = FStar.Tactics.V2 module RUtil = Pulse.Reflection.Util module P = Pulse.Syntax.Printer module PS = Pulse.Checker.Prover.Substs let equational (t:term) : bool = match t.t with | Tm_FStar host_term -> (match R.inspect_ln host_term with | R.Tv_Match _ _ _ -> true | _ -> false) | _ -> false let type_of_fv (g:env) (fv:R.fv) : T.Tac (option R.term) = let n = R.inspect_fv fv in match R.lookup_typ (fstar_env g) n with | None -> None | Some se -> match R.inspect_sigelt se with | R.Unk -> None | R.Sg_Let _ lbs -> ( L.tryPick (fun lb -> let lbv = R.inspect_lb lb in if R.inspect_fv lbv.lb_fv = n then Some lbv.lb_typ else None) lbs ) | R.Sg_Val _ _ t -> Some t | R.Sg_Inductive _nm _univs params typ _ -> None
false
true
Pulse.Checker.Prover.Match.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val is_smt_fallback (t: R.term) : bool
[]
Pulse.Checker.Prover.Match.is_smt_fallback
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: FStar.Reflection.Types.term -> Prims.bool
{ "end_col": 14, "end_line": 54, "start_col": 2, "start_line": 50 }
Prims.Tot
val is_reveal (t: term) : bool
[ { "abbrev": true, "full_module": "Pulse.Checker.Prover.Substs", "short_module": "PS" }, { "abbrev": true, "full_module": "Pulse.Syntax.Printer", "short_module": "P" }, { "abbrev": true, "full_module": "Pulse.Reflection.Util", "short_module": "RUtil" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2.TermEq", "short_module": "TermEq" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let is_reveal (t:term) : bool = match leftmost_head t with | Some hd -> (match is_fvar hd with | Some (l, [_]) -> l = RUtil.reveal_lid | _ -> false) | _ -> false
val is_reveal (t: term) : bool let is_reveal (t: term) : bool =
false
null
false
match leftmost_head t with | Some hd -> (match is_fvar hd with | Some (l, [_]) -> l = RUtil.reveal_lid | _ -> false) | _ -> false
{ "checked_file": "Pulse.Checker.Prover.Match.fst.checked", "dependencies": [ "Pulse.Typing.Util.fsti.checked", "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.Printer.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Prover.Util.fsti.checked", "Pulse.Checker.Prover.Substs.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.TermEq.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.Match.fst" }
[ "total" ]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Pure.leftmost_head", "Pulse.Syntax.Pure.is_fvar", "FStar.Reflection.Types.name", "Pulse.Syntax.Base.universe", "Prims.op_Equality", "Prims.list", "Prims.string", "Pulse.Reflection.Util.reveal_lid", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Prims.bool" ]
[]
module Pulse.Checker.Prover.Match open Pulse.Syntax open Pulse.Typing open Pulse.Typing.Combinators open Pulse.Typing.Metatheory open Pulse.Typing.Util open Pulse.Checker.VPropEquiv open Pulse.Checker.Prover.Base open Pulse.Checker.Prover.Util module L = FStar.List.Tot module R = FStar.Reflection.V2 module TermEq = FStar.Reflection.V2.TermEq module T = FStar.Tactics.V2 module RUtil = Pulse.Reflection.Util module P = Pulse.Syntax.Printer module PS = Pulse.Checker.Prover.Substs let equational (t:term) : bool = match t.t with | Tm_FStar host_term -> (match R.inspect_ln host_term with | R.Tv_Match _ _ _ -> true | _ -> false) | _ -> false let type_of_fv (g:env) (fv:R.fv) : T.Tac (option R.term) = let n = R.inspect_fv fv in match R.lookup_typ (fstar_env g) n with | None -> None | Some se -> match R.inspect_sigelt se with | R.Unk -> None | R.Sg_Let _ lbs -> ( L.tryPick (fun lb -> let lbv = R.inspect_lb lb in if R.inspect_fv lbv.lb_fv = n then Some lbv.lb_typ else None) lbs ) | R.Sg_Val _ _ t -> Some t | R.Sg_Inductive _nm _univs params typ _ -> None let is_smt_fallback (t:R.term) : bool = match R.inspect_ln t with | R.Tv_FVar fv -> let name = R.inspect_fv fv in name = ["Steel";"Effect";"Common";"smt_fallback"] | _ -> false (* When comparing t0 =?= t1, if they are not syntactically equal, we have to decide whether or not we should fire an SMT query to compare them for provable equality. The criterion is as follows: 1. We allow an SMT query if either t0 or t1 is "equational". For now, that means that either is a match expression. 2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un` of the same head symbol `f`, a top-level constant, then we check if the type of `f` decorates any of its binders with the `smt_fallback` attribute. - If none of them are marked as such, then we check if `f v0...` is syntactically equal to `f u0...` and allow an SMT query to check if vn = vm. That is, the default behavior for predicates is that they *last* argument is eligible for SMT equality. - Otherwise, for each binder that is NOT marked as `smt_fallback`, we check if the corresponding argument is syntactically equal. If so, we allow t0 and t1 to be compared for SMT equality. For example, Steel.ST.Reference.pts_to is defined like so: /// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)] /// is unifiable with [pts_to r p (1 + v)] val pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop *) let eligible_for_smt_equality (g:env) (t0 t1:term) : T.Tac bool = let either_equational () = equational t0 || equational t1 in let head_eq (t0 t1:R.term) = match R.inspect_ln t0, R.inspect_ln t1 with | R.Tv_App h0 _, R.Tv_App h1 _ -> TermEq.term_eq h0 h1 | _ -> false in match t0.t, t1.t with | Tm_FStar t0, Tm_FStar t1 -> ( let h0, args0 = R.collect_app_ln t0 in let h1, args1 = R.collect_app_ln t1 in if TermEq.term_eq h0 h1 && L.length args0 = L.length args1 then ( match R.inspect_ln h0 with | R.Tv_FVar fv | R.Tv_UInst fv _ -> ( match type_of_fv g fv with | None -> either_equational() | Some t -> let bs, _ = R.collect_arr_ln_bs t in let is_smt_fallback (b:R.binder) = let bview = R.inspect_binder b in L.existsb is_smt_fallback bview.attrs in let some_fallbacks, fallbacks = L.fold_right (fun b (some_fallbacks, bs) -> if is_smt_fallback b then true, true::bs else some_fallbacks, false::bs) bs (false, []) in if not some_fallbacks then ( //if none of the binders are marked fallback //then, by default, consider only the last argument as //fallback head_eq t0 t1 ) else ( let rec aux args0 args1 fallbacks = match args0, args1, fallbacks with | (a0, _)::args0, (a1, _)::args1, b::fallbacks -> if b then aux args0 args1 fallbacks else if not (TermEq.term_eq a0 a1) then false else aux args0 args1 fallbacks | [], [], [] -> true | _ -> either_equational() //unequal lengths in aux args0 args1 fallbacks ) ) | _ -> either_equational () ) else either_equational () ) | _ -> either_equational () let refl_uvar (t:R.term) (uvs:env) : option var = let open R in match inspect_ln t with | Tv_Var v -> let {uniq=n} = inspect_namedv v in if contains uvs n then Some n else None | _ -> None let is_uvar (t:term) (uvs:env) : option var = match t.t with | Tm_FStar t -> refl_uvar t uvs | _ -> None let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool = not (check_disjoint uvs (freevars t)) let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) = match is_pure_app t with | Some (hd, None, arg) -> (match is_pure_app hd with | Some (hd, Some Implicit, ty) -> let arg_uvar_index_opt = is_uvar arg uvs in (match arg_uvar_index_opt with | Some n -> (match is_fvar hd with | Some (l, [u]) -> if l = RUtil.reveal_lid then Some (u, ty, n) else None | _ -> None) | _ -> None) | _ -> None) | _ -> None
false
true
Pulse.Checker.Prover.Match.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val is_reveal (t: term) : bool
[]
Pulse.Checker.Prover.Match.is_reveal
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: Pulse.Syntax.Base.term -> Prims.bool
{ "end_col": 14, "end_line": 192, "start_col": 2, "start_line": 187 }
Prims.Tot
val is_reveal_uvar (t: term) (uvs: env) : option (universe & term & var)
[ { "abbrev": true, "full_module": "Pulse.Checker.Prover.Substs", "short_module": "PS" }, { "abbrev": true, "full_module": "Pulse.Syntax.Printer", "short_module": "P" }, { "abbrev": true, "full_module": "Pulse.Reflection.Util", "short_module": "RUtil" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2.TermEq", "short_module": "TermEq" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) = match is_pure_app t with | Some (hd, None, arg) -> (match is_pure_app hd with | Some (hd, Some Implicit, ty) -> let arg_uvar_index_opt = is_uvar arg uvs in (match arg_uvar_index_opt with | Some n -> (match is_fvar hd with | Some (l, [u]) -> if l = RUtil.reveal_lid then Some (u, ty, n) else None | _ -> None) | _ -> None) | _ -> None) | _ -> None
val is_reveal_uvar (t: term) (uvs: env) : option (universe & term & var) let is_reveal_uvar (t: term) (uvs: env) : option (universe & term & var) =
false
null
false
match is_pure_app t with | Some (hd, None, arg) -> (match is_pure_app hd with | Some (hd, Some Implicit, ty) -> let arg_uvar_index_opt = is_uvar arg uvs in (match arg_uvar_index_opt with | Some n -> (match is_fvar hd with | Some (l, [u]) -> if l = RUtil.reveal_lid then Some (u, ty, n) else None | _ -> None) | _ -> None) | _ -> None) | _ -> None
{ "checked_file": "Pulse.Checker.Prover.Match.fst.checked", "dependencies": [ "Pulse.Typing.Util.fsti.checked", "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.Printer.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Prover.Util.fsti.checked", "Pulse.Checker.Prover.Substs.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.TermEq.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.Match.fst" }
[ "total" ]
[ "Pulse.Syntax.Base.term", "Pulse.Typing.Env.env", "Pulse.Syntax.Pure.is_pure_app", "Pulse.Syntax.Base.var", "Pulse.Syntax.Pure.is_fvar", "FStar.Reflection.Types.name", "Pulse.Syntax.Base.universe", "Prims.op_Equality", "Prims.list", "Prims.string", "Pulse.Reflection.Util.reveal_lid", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple3", "FStar.Pervasives.Native.Mktuple3", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Pulse.Checker.Prover.Match.is_uvar", "Pulse.Syntax.Base.qualifier" ]
[]
module Pulse.Checker.Prover.Match open Pulse.Syntax open Pulse.Typing open Pulse.Typing.Combinators open Pulse.Typing.Metatheory open Pulse.Typing.Util open Pulse.Checker.VPropEquiv open Pulse.Checker.Prover.Base open Pulse.Checker.Prover.Util module L = FStar.List.Tot module R = FStar.Reflection.V2 module TermEq = FStar.Reflection.V2.TermEq module T = FStar.Tactics.V2 module RUtil = Pulse.Reflection.Util module P = Pulse.Syntax.Printer module PS = Pulse.Checker.Prover.Substs let equational (t:term) : bool = match t.t with | Tm_FStar host_term -> (match R.inspect_ln host_term with | R.Tv_Match _ _ _ -> true | _ -> false) | _ -> false let type_of_fv (g:env) (fv:R.fv) : T.Tac (option R.term) = let n = R.inspect_fv fv in match R.lookup_typ (fstar_env g) n with | None -> None | Some se -> match R.inspect_sigelt se with | R.Unk -> None | R.Sg_Let _ lbs -> ( L.tryPick (fun lb -> let lbv = R.inspect_lb lb in if R.inspect_fv lbv.lb_fv = n then Some lbv.lb_typ else None) lbs ) | R.Sg_Val _ _ t -> Some t | R.Sg_Inductive _nm _univs params typ _ -> None let is_smt_fallback (t:R.term) : bool = match R.inspect_ln t with | R.Tv_FVar fv -> let name = R.inspect_fv fv in name = ["Steel";"Effect";"Common";"smt_fallback"] | _ -> false (* When comparing t0 =?= t1, if they are not syntactically equal, we have to decide whether or not we should fire an SMT query to compare them for provable equality. The criterion is as follows: 1. We allow an SMT query if either t0 or t1 is "equational". For now, that means that either is a match expression. 2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un` of the same head symbol `f`, a top-level constant, then we check if the type of `f` decorates any of its binders with the `smt_fallback` attribute. - If none of them are marked as such, then we check if `f v0...` is syntactically equal to `f u0...` and allow an SMT query to check if vn = vm. That is, the default behavior for predicates is that they *last* argument is eligible for SMT equality. - Otherwise, for each binder that is NOT marked as `smt_fallback`, we check if the corresponding argument is syntactically equal. If so, we allow t0 and t1 to be compared for SMT equality. For example, Steel.ST.Reference.pts_to is defined like so: /// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)] /// is unifiable with [pts_to r p (1 + v)] val pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop *) let eligible_for_smt_equality (g:env) (t0 t1:term) : T.Tac bool = let either_equational () = equational t0 || equational t1 in let head_eq (t0 t1:R.term) = match R.inspect_ln t0, R.inspect_ln t1 with | R.Tv_App h0 _, R.Tv_App h1 _ -> TermEq.term_eq h0 h1 | _ -> false in match t0.t, t1.t with | Tm_FStar t0, Tm_FStar t1 -> ( let h0, args0 = R.collect_app_ln t0 in let h1, args1 = R.collect_app_ln t1 in if TermEq.term_eq h0 h1 && L.length args0 = L.length args1 then ( match R.inspect_ln h0 with | R.Tv_FVar fv | R.Tv_UInst fv _ -> ( match type_of_fv g fv with | None -> either_equational() | Some t -> let bs, _ = R.collect_arr_ln_bs t in let is_smt_fallback (b:R.binder) = let bview = R.inspect_binder b in L.existsb is_smt_fallback bview.attrs in let some_fallbacks, fallbacks = L.fold_right (fun b (some_fallbacks, bs) -> if is_smt_fallback b then true, true::bs else some_fallbacks, false::bs) bs (false, []) in if not some_fallbacks then ( //if none of the binders are marked fallback //then, by default, consider only the last argument as //fallback head_eq t0 t1 ) else ( let rec aux args0 args1 fallbacks = match args0, args1, fallbacks with | (a0, _)::args0, (a1, _)::args1, b::fallbacks -> if b then aux args0 args1 fallbacks else if not (TermEq.term_eq a0 a1) then false else aux args0 args1 fallbacks | [], [], [] -> true | _ -> either_equational() //unequal lengths in aux args0 args1 fallbacks ) ) | _ -> either_equational () ) else either_equational () ) | _ -> either_equational () let refl_uvar (t:R.term) (uvs:env) : option var = let open R in match inspect_ln t with | Tv_Var v -> let {uniq=n} = inspect_namedv v in if contains uvs n then Some n else None | _ -> None let is_uvar (t:term) (uvs:env) : option var = match t.t with | Tm_FStar t -> refl_uvar t uvs | _ -> None let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool = not (check_disjoint uvs (freevars t))
false
true
Pulse.Checker.Prover.Match.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val is_reveal_uvar (t: term) (uvs: env) : option (universe & term & var)
[]
Pulse.Checker.Prover.Match.is_reveal_uvar
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: Pulse.Syntax.Base.term -> uvs: Pulse.Typing.Env.env -> FStar.Pervasives.Native.option ((Pulse.Syntax.Base.universe * Pulse.Syntax.Base.term) * Pulse.Syntax.Base.var)
{ "end_col": 13, "end_line": 184, "start_col": 2, "start_line": 169 }
FStar.Tactics.Effect.Tac
val type_of_fv (g: env) (fv: R.fv) : T.Tac (option R.term)
[ { "abbrev": true, "full_module": "Pulse.Checker.Prover.Substs", "short_module": "PS" }, { "abbrev": true, "full_module": "Pulse.Syntax.Printer", "short_module": "P" }, { "abbrev": true, "full_module": "Pulse.Reflection.Util", "short_module": "RUtil" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2.TermEq", "short_module": "TermEq" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let type_of_fv (g:env) (fv:R.fv) : T.Tac (option R.term) = let n = R.inspect_fv fv in match R.lookup_typ (fstar_env g) n with | None -> None | Some se -> match R.inspect_sigelt se with | R.Unk -> None | R.Sg_Let _ lbs -> ( L.tryPick (fun lb -> let lbv = R.inspect_lb lb in if R.inspect_fv lbv.lb_fv = n then Some lbv.lb_typ else None) lbs ) | R.Sg_Val _ _ t -> Some t | R.Sg_Inductive _nm _univs params typ _ -> None
val type_of_fv (g: env) (fv: R.fv) : T.Tac (option R.term) let type_of_fv (g: env) (fv: R.fv) : T.Tac (option R.term) =
true
null
false
let n = R.inspect_fv fv in match R.lookup_typ (fstar_env g) n with | None -> None | Some se -> match R.inspect_sigelt se with | R.Unk -> None | R.Sg_Let _ lbs -> (L.tryPick (fun lb -> let lbv = R.inspect_lb lb in if R.inspect_fv lbv.lb_fv = n then Some lbv.lb_typ else None) lbs) | R.Sg_Val _ _ t -> Some t | R.Sg_Inductive _nm _univs params typ _ -> None
{ "checked_file": "Pulse.Checker.Prover.Match.fst.checked", "dependencies": [ "Pulse.Typing.Util.fsti.checked", "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.Printer.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Prover.Util.fsti.checked", "Pulse.Checker.Prover.Substs.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.TermEq.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.Match.fst" }
[]
[ "Pulse.Typing.Env.env", "FStar.Reflection.Types.fv", "FStar.Reflection.V2.Builtins.lookup_typ", "Pulse.Typing.Env.fstar_env", "FStar.Pervasives.Native.None", "FStar.Reflection.Types.term", "FStar.Reflection.Types.sigelt", "FStar.Reflection.V2.Builtins.inspect_sigelt", "Prims.bool", "Prims.list", "FStar.Reflection.Types.letbinding", "FStar.List.Tot.Base.tryPick", "FStar.Reflection.Types.typ", "Prims.op_Equality", "FStar.Reflection.Types.name", "FStar.Reflection.V2.Builtins.inspect_fv", "FStar.Reflection.V2.Data.__proj__Mklb_view__item__lb_fv", "FStar.Pervasives.Native.Some", "FStar.Reflection.V2.Data.__proj__Mklb_view__item__lb_typ", "FStar.Pervasives.Native.option", "FStar.Reflection.V2.Data.lb_view", "Prims.precedes", "FStar.Reflection.V2.Builtins.inspect_lb", "FStar.Reflection.Types.univ_name", "FStar.Reflection.Types.binders", "FStar.Reflection.V2.Data.ctor" ]
[]
module Pulse.Checker.Prover.Match open Pulse.Syntax open Pulse.Typing open Pulse.Typing.Combinators open Pulse.Typing.Metatheory open Pulse.Typing.Util open Pulse.Checker.VPropEquiv open Pulse.Checker.Prover.Base open Pulse.Checker.Prover.Util module L = FStar.List.Tot module R = FStar.Reflection.V2 module TermEq = FStar.Reflection.V2.TermEq module T = FStar.Tactics.V2 module RUtil = Pulse.Reflection.Util module P = Pulse.Syntax.Printer module PS = Pulse.Checker.Prover.Substs let equational (t:term) : bool = match t.t with | Tm_FStar host_term -> (match R.inspect_ln host_term with | R.Tv_Match _ _ _ -> true | _ -> false) | _ -> false let type_of_fv (g:env) (fv:R.fv)
false
false
Pulse.Checker.Prover.Match.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val type_of_fv (g: env) (fv: R.fv) : T.Tac (option R.term)
[]
Pulse.Checker.Prover.Match.type_of_fv
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
g: Pulse.Typing.Env.env -> fv: FStar.Reflection.Types.fv -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option FStar.Reflection.Types.term)
{ "end_col": 54, "end_line": 47, "start_col": 3, "start_line": 31 }
Prims.Tot
val coerce_eq: #a: Type -> #b: Type -> x: a -> squash (a == b) -> y: b{y == x}
[ { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "Pulse.Checker.Prover.Substs", "short_module": "PS" }, { "abbrev": true, "full_module": "Pulse.Syntax.Printer", "short_module": "P" }, { "abbrev": true, "full_module": "Pulse.Reflection.Util", "short_module": "RUtil" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2.TermEq", "short_module": "TermEq" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x
val coerce_eq: #a: Type -> #b: Type -> x: a -> squash (a == b) -> y: b{y == x} let coerce_eq (#a: Type) (#b: Type) (x: a) (_: squash (a == b)) : y: b{y == x} =
false
null
false
x
{ "checked_file": "Pulse.Checker.Prover.Match.fst.checked", "dependencies": [ "Pulse.Typing.Util.fsti.checked", "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.Printer.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Prover.Util.fsti.checked", "Pulse.Checker.Prover.Substs.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.TermEq.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.Match.fst" }
[ "total" ]
[ "Prims.squash", "Prims.eq2" ]
[]
module Pulse.Checker.Prover.Match open Pulse.Syntax open Pulse.Typing open Pulse.Typing.Combinators open Pulse.Typing.Metatheory open Pulse.Typing.Util open Pulse.Checker.VPropEquiv open Pulse.Checker.Prover.Base open Pulse.Checker.Prover.Util module L = FStar.List.Tot module R = FStar.Reflection.V2 module TermEq = FStar.Reflection.V2.TermEq module T = FStar.Tactics.V2 module RUtil = Pulse.Reflection.Util module P = Pulse.Syntax.Printer module PS = Pulse.Checker.Prover.Substs let equational (t:term) : bool = match t.t with | Tm_FStar host_term -> (match R.inspect_ln host_term with | R.Tv_Match _ _ _ -> true | _ -> false) | _ -> false let type_of_fv (g:env) (fv:R.fv) : T.Tac (option R.term) = let n = R.inspect_fv fv in match R.lookup_typ (fstar_env g) n with | None -> None | Some se -> match R.inspect_sigelt se with | R.Unk -> None | R.Sg_Let _ lbs -> ( L.tryPick (fun lb -> let lbv = R.inspect_lb lb in if R.inspect_fv lbv.lb_fv = n then Some lbv.lb_typ else None) lbs ) | R.Sg_Val _ _ t -> Some t | R.Sg_Inductive _nm _univs params typ _ -> None let is_smt_fallback (t:R.term) : bool = match R.inspect_ln t with | R.Tv_FVar fv -> let name = R.inspect_fv fv in name = ["Steel";"Effect";"Common";"smt_fallback"] | _ -> false (* When comparing t0 =?= t1, if they are not syntactically equal, we have to decide whether or not we should fire an SMT query to compare them for provable equality. The criterion is as follows: 1. We allow an SMT query if either t0 or t1 is "equational". For now, that means that either is a match expression. 2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un` of the same head symbol `f`, a top-level constant, then we check if the type of `f` decorates any of its binders with the `smt_fallback` attribute. - If none of them are marked as such, then we check if `f v0...` is syntactically equal to `f u0...` and allow an SMT query to check if vn = vm. That is, the default behavior for predicates is that they *last* argument is eligible for SMT equality. - Otherwise, for each binder that is NOT marked as `smt_fallback`, we check if the corresponding argument is syntactically equal. If so, we allow t0 and t1 to be compared for SMT equality. For example, Steel.ST.Reference.pts_to is defined like so: /// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)] /// is unifiable with [pts_to r p (1 + v)] val pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop *) let eligible_for_smt_equality (g:env) (t0 t1:term) : T.Tac bool = let either_equational () = equational t0 || equational t1 in let head_eq (t0 t1:R.term) = match R.inspect_ln t0, R.inspect_ln t1 with | R.Tv_App h0 _, R.Tv_App h1 _ -> TermEq.term_eq h0 h1 | _ -> false in match t0.t, t1.t with | Tm_FStar t0, Tm_FStar t1 -> ( let h0, args0 = R.collect_app_ln t0 in let h1, args1 = R.collect_app_ln t1 in if TermEq.term_eq h0 h1 && L.length args0 = L.length args1 then ( match R.inspect_ln h0 with | R.Tv_FVar fv | R.Tv_UInst fv _ -> ( match type_of_fv g fv with | None -> either_equational() | Some t -> let bs, _ = R.collect_arr_ln_bs t in let is_smt_fallback (b:R.binder) = let bview = R.inspect_binder b in L.existsb is_smt_fallback bview.attrs in let some_fallbacks, fallbacks = L.fold_right (fun b (some_fallbacks, bs) -> if is_smt_fallback b then true, true::bs else some_fallbacks, false::bs) bs (false, []) in if not some_fallbacks then ( //if none of the binders are marked fallback //then, by default, consider only the last argument as //fallback head_eq t0 t1 ) else ( let rec aux args0 args1 fallbacks = match args0, args1, fallbacks with | (a0, _)::args0, (a1, _)::args1, b::fallbacks -> if b then aux args0 args1 fallbacks else if not (TermEq.term_eq a0 a1) then false else aux args0 args1 fallbacks | [], [], [] -> true | _ -> either_equational() //unequal lengths in aux args0 args1 fallbacks ) ) | _ -> either_equational () ) else either_equational () ) | _ -> either_equational () let refl_uvar (t:R.term) (uvs:env) : option var = let open R in match inspect_ln t with | Tv_Var v -> let {uniq=n} = inspect_namedv v in if contains uvs n then Some n else None | _ -> None let is_uvar (t:term) (uvs:env) : option var = match t.t with | Tm_FStar t -> refl_uvar t uvs | _ -> None let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool = not (check_disjoint uvs (freevars t)) let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) = match is_pure_app t with | Some (hd, None, arg) -> (match is_pure_app hd with | Some (hd, Some Implicit, ty) -> let arg_uvar_index_opt = is_uvar arg uvs in (match arg_uvar_index_opt with | Some n -> (match is_fvar hd with | Some (l, [u]) -> if l = RUtil.reveal_lid then Some (u, ty, n) else None | _ -> None) | _ -> None) | _ -> None) | _ -> None let is_reveal (t:term) : bool = match leftmost_head t with | Some hd -> (match is_fvar hd with | Some (l, [_]) -> l = RUtil.reveal_lid | _ -> false) | _ -> false module RT = FStar.Reflection.Typing let rec try_solve_uvars (g:env) (uvs:env { disjoint uvs g }) (p q:term) : T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q }) = assume (Set.equal (PS.dom PS.empty) Set.empty); if not (contains_uvar q uvs g) then PS.empty else begin match is_reveal_uvar q uvs, is_reveal p with | Some (u, ty, n), false -> let w = mk_hide u ty p in assume (~ (PS.contains PS.empty n)); let ss = PS.push PS.empty n w in assume (n `Set.mem` freevars q); assume (Set.equal (PS.dom ss) (Set.singleton n)); ss | _ -> match is_uvar q uvs with | Some n -> let w = p in assume (~ (PS.contains PS.empty n)); let ss = PS.push PS.empty n w in assume (n `Set.mem` freevars q); assume (Set.equal (PS.dom ss) (Set.singleton n)); ss | _ -> match p.t, q.t with | Tm_Pure p1, Tm_Pure q1 -> try_solve_uvars g uvs p1 q1 | _, _ -> match is_pure_app p, is_pure_app q with | Some (head_p, qual_p, arg_p), Some (head_q, qual_q, arg_q) -> let ss_head = try_solve_uvars g uvs head_p head_q in let ss_arg = try_solve_uvars g uvs arg_p arg_q in if PS.check_disjoint ss_head ss_arg // TODO: should implement a better compose then begin let ss = PS.push_ss ss_head ss_arg in assume (Set.equal (PS.dom ss) (Set.union (PS.dom ss_head) (PS.dom ss_arg))); assume ((Set.union (freevars head_q) (freevars arg_q)) `Set.subset` freevars q); ss end else PS.empty | _, _ -> PS.empty end let unify (g:env) (uvs:env { disjoint uvs g}) (p q:term) : T.Tac (option (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } & RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q)))) = let ss = try_solve_uvars g uvs p q in let q = ss.(q) in if eq_tm p q then Some (| ss, RT.Rel_refl _ _ _ |) else if contains_uvar q uvs g then None else if eligible_for_smt_equality g p q then let v0 = elab_term p in let v1 = elab_term q in match check_equiv_now (elab_env g) v0 v1 with | Some token, _ -> Some (| ss, RT.Rel_eq_token _ _ _ (FStar.Squash.return_squash token) |) | None, _ -> None else None let try_match_pq (g:env) (uvs:env { disjoint uvs g}) (p q:vprop) : T.Tac (option (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } & vprop_equiv g p ss.(q))) = let r = unify g uvs p q in match r with | None -> None | Some (| ss, _ |) -> let ss : ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } = ss in Some (| ss, magic () |)
false
false
Pulse.Checker.Prover.Match.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val coerce_eq: #a: Type -> #b: Type -> x: a -> squash (a == b) -> y: b{y == x}
[]
Pulse.Checker.Prover.Match.coerce_eq
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
x: a -> _: Prims.squash (a == b) -> y: b{y == x}
{ "end_col": 70, "end_line": 272, "start_col": 69, "start_line": 272 }
FStar.Tactics.Effect.Tac
val eligible_for_smt_equality (g: env) (t0 t1: term) : T.Tac bool
[ { "abbrev": true, "full_module": "Pulse.Checker.Prover.Substs", "short_module": "PS" }, { "abbrev": true, "full_module": "Pulse.Syntax.Printer", "short_module": "P" }, { "abbrev": true, "full_module": "Pulse.Reflection.Util", "short_module": "RUtil" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2.TermEq", "short_module": "TermEq" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let eligible_for_smt_equality (g:env) (t0 t1:term) : T.Tac bool = let either_equational () = equational t0 || equational t1 in let head_eq (t0 t1:R.term) = match R.inspect_ln t0, R.inspect_ln t1 with | R.Tv_App h0 _, R.Tv_App h1 _ -> TermEq.term_eq h0 h1 | _ -> false in match t0.t, t1.t with | Tm_FStar t0, Tm_FStar t1 -> ( let h0, args0 = R.collect_app_ln t0 in let h1, args1 = R.collect_app_ln t1 in if TermEq.term_eq h0 h1 && L.length args0 = L.length args1 then ( match R.inspect_ln h0 with | R.Tv_FVar fv | R.Tv_UInst fv _ -> ( match type_of_fv g fv with | None -> either_equational() | Some t -> let bs, _ = R.collect_arr_ln_bs t in let is_smt_fallback (b:R.binder) = let bview = R.inspect_binder b in L.existsb is_smt_fallback bview.attrs in let some_fallbacks, fallbacks = L.fold_right (fun b (some_fallbacks, bs) -> if is_smt_fallback b then true, true::bs else some_fallbacks, false::bs) bs (false, []) in if not some_fallbacks then ( //if none of the binders are marked fallback //then, by default, consider only the last argument as //fallback head_eq t0 t1 ) else ( let rec aux args0 args1 fallbacks = match args0, args1, fallbacks with | (a0, _)::args0, (a1, _)::args1, b::fallbacks -> if b then aux args0 args1 fallbacks else if not (TermEq.term_eq a0 a1) then false else aux args0 args1 fallbacks | [], [], [] -> true | _ -> either_equational() //unequal lengths in aux args0 args1 fallbacks ) ) | _ -> either_equational () ) else either_equational () ) | _ -> either_equational ()
val eligible_for_smt_equality (g: env) (t0 t1: term) : T.Tac bool let eligible_for_smt_equality (g: env) (t0 t1: term) : T.Tac bool =
true
null
false
let either_equational () = equational t0 || equational t1 in let head_eq (t0 t1: R.term) = match R.inspect_ln t0, R.inspect_ln t1 with | R.Tv_App h0 _, R.Tv_App h1 _ -> TermEq.term_eq h0 h1 | _ -> false in match t0.t, t1.t with | Tm_FStar t0, Tm_FStar t1 -> (let h0, args0 = R.collect_app_ln t0 in let h1, args1 = R.collect_app_ln t1 in if TermEq.term_eq h0 h1 && L.length args0 = L.length args1 then (match R.inspect_ln h0 with | R.Tv_FVar fv | R.Tv_UInst fv _ -> (match type_of_fv g fv with | None -> either_equational () | Some t -> let bs, _ = R.collect_arr_ln_bs t in let is_smt_fallback (b: R.binder) = let bview = R.inspect_binder b in L.existsb is_smt_fallback bview.attrs in let some_fallbacks, fallbacks = L.fold_right (fun b (some_fallbacks, bs) -> if is_smt_fallback b then true, true :: bs else some_fallbacks, false :: bs) bs (false, []) in if not some_fallbacks then (head_eq t0 t1) else (let rec aux args0 args1 fallbacks = match args0, args1, fallbacks with | (a0, _) :: args0, (a1, _) :: args1, b :: fallbacks -> if b then aux args0 args1 fallbacks else if not (TermEq.term_eq a0 a1) then false else aux args0 args1 fallbacks | [], [], [] -> true | _ -> either_equational () in aux args0 args1 fallbacks)) | _ -> either_equational ()) else either_equational ()) | _ -> either_equational ()
{ "checked_file": "Pulse.Checker.Prover.Match.fst.checked", "dependencies": [ "Pulse.Typing.Util.fsti.checked", "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.Printer.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Prover.Util.fsti.checked", "Pulse.Checker.Prover.Substs.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.TermEq.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.Match.fst" }
[]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.term", "FStar.Pervasives.Native.Mktuple2", "Pulse.Syntax.Base.term'", "Pulse.Syntax.Base.__proj__Mkterm__item__t", "Pulse.Syntax.Base.host_term", "FStar.Reflection.Types.term", "Prims.list", "FStar.Reflection.V2.Data.argv", "Prims.op_AmpAmp", "FStar.Reflection.V2.TermEq.term_eq", "Prims.op_Equality", "Prims.nat", "FStar.List.Tot.Base.length", "FStar.Reflection.V2.Builtins.inspect_ln", "FStar.Reflection.Types.fv", "FStar.Reflection.Types.binder", "FStar.Reflection.Types.comp", "Prims.bool", "Prims.op_Negation", "FStar.Pervasives.Native.tuple2", "FStar.Reflection.V2.Data.aqualv", "FStar.Pervasives.Native.Mktuple3", "FStar.Pervasives.Native.tuple3", "FStar.List.Tot.Base.fold_right", "Prims.Cons", "Prims.Nil", "FStar.List.Tot.Base.existsb", "Pulse.Checker.Prover.Match.is_smt_fallback", "FStar.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs", "FStar.Reflection.V2.Data.binder_view", "Prims.precedes", "FStar.Reflection.V2.Builtins.inspect_binder", "FStar.Reflection.V2.Derived.collect_arr_ln_bs", "FStar.Pervasives.Native.option", "Pulse.Checker.Prover.Match.type_of_fv", "FStar.Reflection.V2.Data.universes", "FStar.Reflection.V2.Data.term_view", "FStar.Reflection.V2.Derived.collect_app_ln", "Prims.unit", "Prims.op_BarBar", "Pulse.Checker.Prover.Match.equational" ]
[]
module Pulse.Checker.Prover.Match open Pulse.Syntax open Pulse.Typing open Pulse.Typing.Combinators open Pulse.Typing.Metatheory open Pulse.Typing.Util open Pulse.Checker.VPropEquiv open Pulse.Checker.Prover.Base open Pulse.Checker.Prover.Util module L = FStar.List.Tot module R = FStar.Reflection.V2 module TermEq = FStar.Reflection.V2.TermEq module T = FStar.Tactics.V2 module RUtil = Pulse.Reflection.Util module P = Pulse.Syntax.Printer module PS = Pulse.Checker.Prover.Substs let equational (t:term) : bool = match t.t with | Tm_FStar host_term -> (match R.inspect_ln host_term with | R.Tv_Match _ _ _ -> true | _ -> false) | _ -> false let type_of_fv (g:env) (fv:R.fv) : T.Tac (option R.term) = let n = R.inspect_fv fv in match R.lookup_typ (fstar_env g) n with | None -> None | Some se -> match R.inspect_sigelt se with | R.Unk -> None | R.Sg_Let _ lbs -> ( L.tryPick (fun lb -> let lbv = R.inspect_lb lb in if R.inspect_fv lbv.lb_fv = n then Some lbv.lb_typ else None) lbs ) | R.Sg_Val _ _ t -> Some t | R.Sg_Inductive _nm _univs params typ _ -> None let is_smt_fallback (t:R.term) : bool = match R.inspect_ln t with | R.Tv_FVar fv -> let name = R.inspect_fv fv in name = ["Steel";"Effect";"Common";"smt_fallback"] | _ -> false (* When comparing t0 =?= t1, if they are not syntactically equal, we have to decide whether or not we should fire an SMT query to compare them for provable equality. The criterion is as follows: 1. We allow an SMT query if either t0 or t1 is "equational". For now, that means that either is a match expression. 2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un` of the same head symbol `f`, a top-level constant, then we check if the type of `f` decorates any of its binders with the `smt_fallback` attribute. - If none of them are marked as such, then we check if `f v0...` is syntactically equal to `f u0...` and allow an SMT query to check if vn = vm. That is, the default behavior for predicates is that they *last* argument is eligible for SMT equality. - Otherwise, for each binder that is NOT marked as `smt_fallback`, we check if the corresponding argument is syntactically equal. If so, we allow t0 and t1 to be compared for SMT equality. For example, Steel.ST.Reference.pts_to is defined like so: /// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)] /// is unifiable with [pts_to r p (1 + v)] val pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop *) let eligible_for_smt_equality (g:env) (t0 t1:term)
false
false
Pulse.Checker.Prover.Match.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eligible_for_smt_equality (g: env) (t0 t1: term) : T.Tac bool
[]
Pulse.Checker.Prover.Match.eligible_for_smt_equality
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
g: Pulse.Typing.Env.env -> t0: Pulse.Syntax.Base.term -> t1: Pulse.Syntax.Base.term -> FStar.Tactics.Effect.Tac Prims.bool
{ "end_col": 31, "end_line": 149, "start_col": 3, "start_line": 91 }
FStar.Tactics.Effect.Tac
val unify (g: env) (uvs: env{disjoint uvs g}) (p q: term) : T.Tac (option (ss: PS.ss_t{(PS.dom ss) `Set.subset` (freevars q)} & RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q))))
[ { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "Pulse.Checker.Prover.Substs", "short_module": "PS" }, { "abbrev": true, "full_module": "Pulse.Syntax.Printer", "short_module": "P" }, { "abbrev": true, "full_module": "Pulse.Reflection.Util", "short_module": "RUtil" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2.TermEq", "short_module": "TermEq" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let unify (g:env) (uvs:env { disjoint uvs g}) (p q:term) : T.Tac (option (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } & RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q)))) = let ss = try_solve_uvars g uvs p q in let q = ss.(q) in if eq_tm p q then Some (| ss, RT.Rel_refl _ _ _ |) else if contains_uvar q uvs g then None else if eligible_for_smt_equality g p q then let v0 = elab_term p in let v1 = elab_term q in match check_equiv_now (elab_env g) v0 v1 with | Some token, _ -> Some (| ss, RT.Rel_eq_token _ _ _ (FStar.Squash.return_squash token) |) | None, _ -> None else None
val unify (g: env) (uvs: env{disjoint uvs g}) (p q: term) : T.Tac (option (ss: PS.ss_t{(PS.dom ss) `Set.subset` (freevars q)} & RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q)))) let unify (g: env) (uvs: env{disjoint uvs g}) (p q: term) : T.Tac (option (ss: PS.ss_t{(PS.dom ss) `Set.subset` (freevars q)} & RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q)))) =
true
null
false
let ss = try_solve_uvars g uvs p q in let q = ss.(q) in if eq_tm p q then Some (| ss, RT.Rel_refl _ _ _ |) else if contains_uvar q uvs g then None else if eligible_for_smt_equality g p q then let v0 = elab_term p in let v1 = elab_term q in match check_equiv_now (elab_env g) v0 v1 with | Some token, _ -> Some (| ss, RT.Rel_eq_token _ _ _ (FStar.Squash.return_squash token) |) | None, _ -> None else None
{ "checked_file": "Pulse.Checker.Prover.Match.fst.checked", "dependencies": [ "Pulse.Typing.Util.fsti.checked", "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.Printer.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Prover.Util.fsti.checked", "Pulse.Checker.Prover.Substs.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.TermEq.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.Match.fst" }
[]
[ "Pulse.Typing.Env.env", "Pulse.Typing.Env.disjoint", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.eq_tm", "FStar.Pervasives.Native.Some", "Prims.dtuple2", "Pulse.Checker.Prover.Substs.ss_t", "FStar.Set.subset", "Pulse.Syntax.Base.var", "Pulse.Checker.Prover.Substs.dom", "Pulse.Syntax.Naming.freevars", "FStar.Reflection.Typing.equiv", "Pulse.Typing.elab_env", "Pulse.Elaborate.Pure.elab_term", "Pulse.Checker.Prover.Base.op_Array_Access", "Prims.Mkdtuple2", "FStar.Reflection.Typing.Rel_refl", "FStar.Reflection.Typing.R_Eq", "FStar.Pervasives.Native.option", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.Tactics.Types.equiv_token", "FStar.Tactics.Types.issues", "FStar.Reflection.Typing.Rel_eq_token", "FStar.Squash.return_squash", "FStar.Pervasives.Native.tuple2", "Pulse.Typing.Util.check_equiv_now", "FStar.Reflection.Types.term", "Pulse.Checker.Prover.Match.eligible_for_smt_equality", "Pulse.Checker.Prover.Match.contains_uvar", "Pulse.Checker.Prover.Match.try_solve_uvars" ]
[]
module Pulse.Checker.Prover.Match open Pulse.Syntax open Pulse.Typing open Pulse.Typing.Combinators open Pulse.Typing.Metatheory open Pulse.Typing.Util open Pulse.Checker.VPropEquiv open Pulse.Checker.Prover.Base open Pulse.Checker.Prover.Util module L = FStar.List.Tot module R = FStar.Reflection.V2 module TermEq = FStar.Reflection.V2.TermEq module T = FStar.Tactics.V2 module RUtil = Pulse.Reflection.Util module P = Pulse.Syntax.Printer module PS = Pulse.Checker.Prover.Substs let equational (t:term) : bool = match t.t with | Tm_FStar host_term -> (match R.inspect_ln host_term with | R.Tv_Match _ _ _ -> true | _ -> false) | _ -> false let type_of_fv (g:env) (fv:R.fv) : T.Tac (option R.term) = let n = R.inspect_fv fv in match R.lookup_typ (fstar_env g) n with | None -> None | Some se -> match R.inspect_sigelt se with | R.Unk -> None | R.Sg_Let _ lbs -> ( L.tryPick (fun lb -> let lbv = R.inspect_lb lb in if R.inspect_fv lbv.lb_fv = n then Some lbv.lb_typ else None) lbs ) | R.Sg_Val _ _ t -> Some t | R.Sg_Inductive _nm _univs params typ _ -> None let is_smt_fallback (t:R.term) : bool = match R.inspect_ln t with | R.Tv_FVar fv -> let name = R.inspect_fv fv in name = ["Steel";"Effect";"Common";"smt_fallback"] | _ -> false (* When comparing t0 =?= t1, if they are not syntactically equal, we have to decide whether or not we should fire an SMT query to compare them for provable equality. The criterion is as follows: 1. We allow an SMT query if either t0 or t1 is "equational". For now, that means that either is a match expression. 2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un` of the same head symbol `f`, a top-level constant, then we check if the type of `f` decorates any of its binders with the `smt_fallback` attribute. - If none of them are marked as such, then we check if `f v0...` is syntactically equal to `f u0...` and allow an SMT query to check if vn = vm. That is, the default behavior for predicates is that they *last* argument is eligible for SMT equality. - Otherwise, for each binder that is NOT marked as `smt_fallback`, we check if the corresponding argument is syntactically equal. If so, we allow t0 and t1 to be compared for SMT equality. For example, Steel.ST.Reference.pts_to is defined like so: /// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)] /// is unifiable with [pts_to r p (1 + v)] val pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop *) let eligible_for_smt_equality (g:env) (t0 t1:term) : T.Tac bool = let either_equational () = equational t0 || equational t1 in let head_eq (t0 t1:R.term) = match R.inspect_ln t0, R.inspect_ln t1 with | R.Tv_App h0 _, R.Tv_App h1 _ -> TermEq.term_eq h0 h1 | _ -> false in match t0.t, t1.t with | Tm_FStar t0, Tm_FStar t1 -> ( let h0, args0 = R.collect_app_ln t0 in let h1, args1 = R.collect_app_ln t1 in if TermEq.term_eq h0 h1 && L.length args0 = L.length args1 then ( match R.inspect_ln h0 with | R.Tv_FVar fv | R.Tv_UInst fv _ -> ( match type_of_fv g fv with | None -> either_equational() | Some t -> let bs, _ = R.collect_arr_ln_bs t in let is_smt_fallback (b:R.binder) = let bview = R.inspect_binder b in L.existsb is_smt_fallback bview.attrs in let some_fallbacks, fallbacks = L.fold_right (fun b (some_fallbacks, bs) -> if is_smt_fallback b then true, true::bs else some_fallbacks, false::bs) bs (false, []) in if not some_fallbacks then ( //if none of the binders are marked fallback //then, by default, consider only the last argument as //fallback head_eq t0 t1 ) else ( let rec aux args0 args1 fallbacks = match args0, args1, fallbacks with | (a0, _)::args0, (a1, _)::args1, b::fallbacks -> if b then aux args0 args1 fallbacks else if not (TermEq.term_eq a0 a1) then false else aux args0 args1 fallbacks | [], [], [] -> true | _ -> either_equational() //unequal lengths in aux args0 args1 fallbacks ) ) | _ -> either_equational () ) else either_equational () ) | _ -> either_equational () let refl_uvar (t:R.term) (uvs:env) : option var = let open R in match inspect_ln t with | Tv_Var v -> let {uniq=n} = inspect_namedv v in if contains uvs n then Some n else None | _ -> None let is_uvar (t:term) (uvs:env) : option var = match t.t with | Tm_FStar t -> refl_uvar t uvs | _ -> None let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool = not (check_disjoint uvs (freevars t)) let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) = match is_pure_app t with | Some (hd, None, arg) -> (match is_pure_app hd with | Some (hd, Some Implicit, ty) -> let arg_uvar_index_opt = is_uvar arg uvs in (match arg_uvar_index_opt with | Some n -> (match is_fvar hd with | Some (l, [u]) -> if l = RUtil.reveal_lid then Some (u, ty, n) else None | _ -> None) | _ -> None) | _ -> None) | _ -> None let is_reveal (t:term) : bool = match leftmost_head t with | Some hd -> (match is_fvar hd with | Some (l, [_]) -> l = RUtil.reveal_lid | _ -> false) | _ -> false module RT = FStar.Reflection.Typing let rec try_solve_uvars (g:env) (uvs:env { disjoint uvs g }) (p q:term) : T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q }) = assume (Set.equal (PS.dom PS.empty) Set.empty); if not (contains_uvar q uvs g) then PS.empty else begin match is_reveal_uvar q uvs, is_reveal p with | Some (u, ty, n), false -> let w = mk_hide u ty p in assume (~ (PS.contains PS.empty n)); let ss = PS.push PS.empty n w in assume (n `Set.mem` freevars q); assume (Set.equal (PS.dom ss) (Set.singleton n)); ss | _ -> match is_uvar q uvs with | Some n -> let w = p in assume (~ (PS.contains PS.empty n)); let ss = PS.push PS.empty n w in assume (n `Set.mem` freevars q); assume (Set.equal (PS.dom ss) (Set.singleton n)); ss | _ -> match p.t, q.t with | Tm_Pure p1, Tm_Pure q1 -> try_solve_uvars g uvs p1 q1 | _, _ -> match is_pure_app p, is_pure_app q with | Some (head_p, qual_p, arg_p), Some (head_q, qual_q, arg_q) -> let ss_head = try_solve_uvars g uvs head_p head_q in let ss_arg = try_solve_uvars g uvs arg_p arg_q in if PS.check_disjoint ss_head ss_arg // TODO: should implement a better compose then begin let ss = PS.push_ss ss_head ss_arg in assume (Set.equal (PS.dom ss) (Set.union (PS.dom ss_head) (PS.dom ss_arg))); assume ((Set.union (freevars head_q) (freevars arg_q)) `Set.subset` freevars q); ss end else PS.empty | _, _ -> PS.empty end let unify (g:env) (uvs:env { disjoint uvs g}) (p q:term)
false
false
Pulse.Checker.Prover.Match.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val unify (g: env) (uvs: env{disjoint uvs g}) (p q: term) : T.Tac (option (ss: PS.ss_t{(PS.dom ss) `Set.subset` (freevars q)} & RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q))))
[]
Pulse.Checker.Prover.Match.unify
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
g: Pulse.Typing.Env.env -> uvs: Pulse.Typing.Env.env{Pulse.Typing.Env.disjoint uvs g} -> p: Pulse.Syntax.Base.term -> q: Pulse.Syntax.Base.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option (Prims.dtuple2 (ss: Pulse.Checker.Prover.Substs.ss_t { FStar.Set.subset (Pulse.Checker.Prover.Substs.dom ss) (Pulse.Syntax.Naming.freevars q) }) (fun ss -> FStar.Reflection.Typing.equiv (Pulse.Typing.elab_env g) (Pulse.Elaborate.Pure.elab_term p) (Pulse.Elaborate.Pure.elab_term ss.(q)))))
{ "end_col": 11, "end_line": 259, "start_col": 77, "start_line": 245 }
Prims.Tot
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let a_spec = S.aff_point_c
let a_spec =
false
null
false
S.aff_point_c
{ "checked_file": "Hacl.Impl.Ed25519.Group.fst.checked", "dependencies": [ "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Impl.Ed25519.PointDouble.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.PointAdd.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.Group.fst" }
[ "total" ]
[ "Spec.Ed25519.aff_point_c" ]
[]
module Hacl.Impl.Ed25519.Group module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 open Hacl.Impl.Ed25519.PointConstants module LSeq = Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module BE = Hacl.Impl.Exponentiation.Definitions module S = Spec.Ed25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
false
true
Hacl.Impl.Ed25519.Group.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val a_spec : Type0
[]
Hacl.Impl.Ed25519.Group.a_spec
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Group.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 26, "end_line": 21, "start_col": 13, "start_line": 21 }
Prims.Tot
val linv_ctx (a: LSeq.lseq uint64 0) : Type0
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True
val linv_ctx (a: LSeq.lseq uint64 0) : Type0 let linv_ctx (a: LSeq.lseq uint64 0) : Type0 =
false
null
false
True
{ "checked_file": "Hacl.Impl.Ed25519.Group.fst.checked", "dependencies": [ "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Impl.Ed25519.PointDouble.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.PointAdd.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.Group.fst" }
[ "total" ]
[ "Lib.Sequence.lseq", "Lib.IntTypes.uint64", "Prims.l_True" ]
[]
module Hacl.Impl.Ed25519.Group module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 open Hacl.Impl.Ed25519.PointConstants module LSeq = Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module BE = Hacl.Impl.Exponentiation.Definitions module S = Spec.Ed25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let a_spec = S.aff_point_c unfold let refl (a:LSeq.lseq uint64 20{F51.linv a}) : GTot a_spec = S.to_aff_point (F51.refl_ext_point a)
false
false
Hacl.Impl.Ed25519.Group.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val linv_ctx (a: LSeq.lseq uint64 0) : Type0
[]
Hacl.Impl.Ed25519.Group.linv_ctx
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Group.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Lib.Sequence.lseq Lib.IntTypes.uint64 0 -> Type0
{ "end_col": 50, "end_line": 28, "start_col": 46, "start_line": 28 }
Prims.Tot
val mk_to_ed25519_comm_monoid:BE.to_comm_monoid U64 20ul 0ul
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_to_ed25519_comm_monoid : BE.to_comm_monoid U64 20ul 0ul = { BE.a_spec = a_spec; BE.comm_monoid = S.mk_ed25519_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = F51.linv; BE.refl = refl; }
val mk_to_ed25519_comm_monoid:BE.to_comm_monoid U64 20ul 0ul let mk_to_ed25519_comm_monoid:BE.to_comm_monoid U64 20ul 0ul =
false
null
false
{ BE.a_spec = a_spec; BE.comm_monoid = S.mk_ed25519_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = F51.linv; BE.refl = refl }
{ "checked_file": "Hacl.Impl.Ed25519.Group.fst.checked", "dependencies": [ "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Impl.Ed25519.PointDouble.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.PointAdd.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.Group.fst" }
[ "total" ]
[ "Hacl.Impl.Exponentiation.Definitions.Mkto_comm_monoid", "Lib.IntTypes.U64", "FStar.UInt32.uint_to_t", "Hacl.Impl.Ed25519.Group.a_spec", "Spec.Ed25519.mk_ed25519_comm_monoid", "Hacl.Impl.Ed25519.Group.linv_ctx", "Hacl.Impl.Ed25519.Field51.linv", "Hacl.Impl.Ed25519.Group.refl" ]
[]
module Hacl.Impl.Ed25519.Group module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 open Hacl.Impl.Ed25519.PointConstants module LSeq = Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module BE = Hacl.Impl.Exponentiation.Definitions module S = Spec.Ed25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let a_spec = S.aff_point_c unfold let refl (a:LSeq.lseq uint64 20{F51.linv a}) : GTot a_spec = S.to_aff_point (F51.refl_ext_point a) unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True inline_for_extraction noextract
false
false
Hacl.Impl.Ed25519.Group.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_to_ed25519_comm_monoid:BE.to_comm_monoid U64 20ul 0ul
[]
Hacl.Impl.Ed25519.Group.mk_to_ed25519_comm_monoid
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Group.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Exponentiation.Definitions.to_comm_monoid Lib.IntTypes.U64 (FStar.UInt32.uint_to_t 20 <: FStar.UInt32.t) (FStar.UInt32.uint_to_t 0 <: FStar.UInt32.t)
{ "end_col": 17, "end_line": 36, "start_col": 2, "start_line": 32 }
Prims.Tot
val mk_ed25519_concrete_ops:BE.concrete_ops U64 20ul 0ul
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_ed25519_concrete_ops : BE.concrete_ops U64 20ul 0ul = { BE.to = mk_to_ed25519_comm_monoid; BE.lone = point_zero; BE.lmul = point_add; BE.lsqr = point_double; }
val mk_ed25519_concrete_ops:BE.concrete_ops U64 20ul 0ul let mk_ed25519_concrete_ops:BE.concrete_ops U64 20ul 0ul =
false
null
false
{ BE.to = mk_to_ed25519_comm_monoid; BE.lone = point_zero; BE.lmul = point_add; BE.lsqr = point_double }
{ "checked_file": "Hacl.Impl.Ed25519.Group.fst.checked", "dependencies": [ "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Impl.Ed25519.PointDouble.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.PointAdd.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.Group.fst" }
[ "total" ]
[ "Hacl.Impl.Exponentiation.Definitions.Mkconcrete_ops", "Lib.IntTypes.U64", "FStar.UInt32.uint_to_t", "FStar.Ghost.hide", "Hacl.Impl.Exponentiation.Definitions.to_comm_monoid", "Hacl.Impl.Ed25519.Group.mk_to_ed25519_comm_monoid", "Hacl.Impl.Ed25519.Group.point_zero", "Hacl.Impl.Ed25519.Group.point_add", "Hacl.Impl.Ed25519.Group.point_double" ]
[]
module Hacl.Impl.Ed25519.Group module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 open Hacl.Impl.Ed25519.PointConstants module LSeq = Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module BE = Hacl.Impl.Exponentiation.Definitions module S = Spec.Ed25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let a_spec = S.aff_point_c unfold let refl (a:LSeq.lseq uint64 20{F51.linv a}) : GTot a_spec = S.to_aff_point (F51.refl_ext_point a) unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True inline_for_extraction noextract let mk_to_ed25519_comm_monoid : BE.to_comm_monoid U64 20ul 0ul = { BE.a_spec = a_spec; BE.comm_monoid = S.mk_ed25519_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = F51.linv; BE.refl = refl; } inline_for_extraction noextract val point_add : BE.lmul_st U64 20ul 0ul mk_to_ed25519_comm_monoid let point_add ctx x y xy = let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_add_lemma (F51.refl_ext_point (as_seq h0 x)) (F51.refl_ext_point (as_seq h0 y)); Hacl.Impl.Ed25519.PointAdd.point_add xy x y inline_for_extraction noextract val point_double : BE.lsqr_st U64 20ul 0ul mk_to_ed25519_comm_monoid let point_double ctx x xx = let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_double_lemma (F51.refl_ext_point (as_seq h0 x)); Hacl.Impl.Ed25519.PointDouble.point_double xx x inline_for_extraction noextract val point_zero : BE.lone_st U64 20ul 0ul mk_to_ed25519_comm_monoid let point_zero ctx one = make_point_inf one inline_for_extraction noextract
false
false
Hacl.Impl.Ed25519.Group.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_ed25519_concrete_ops:BE.concrete_ops U64 20ul 0ul
[]
Hacl.Impl.Ed25519.Group.mk_ed25519_concrete_ops
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Group.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Exponentiation.Definitions.concrete_ops Lib.IntTypes.U64 (FStar.UInt32.uint_to_t 20 <: FStar.UInt32.t) (FStar.UInt32.uint_to_t 0 <: FStar.UInt32.t)
{ "end_col": 25, "end_line": 67, "start_col": 2, "start_line": 64 }
Prims.GTot
val refl (a: LSeq.lseq uint64 20 {F51.linv a}) : GTot a_spec
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let refl (a:LSeq.lseq uint64 20{F51.linv a}) : GTot a_spec = S.to_aff_point (F51.refl_ext_point a)
val refl (a: LSeq.lseq uint64 20 {F51.linv a}) : GTot a_spec let refl (a: LSeq.lseq uint64 20 {F51.linv a}) : GTot a_spec =
false
null
false
S.to_aff_point (F51.refl_ext_point a)
{ "checked_file": "Hacl.Impl.Ed25519.Group.fst.checked", "dependencies": [ "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Impl.Ed25519.PointDouble.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.PointAdd.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.Group.fst" }
[ "sometrivial" ]
[ "Lib.Sequence.lseq", "Lib.IntTypes.uint64", "Hacl.Impl.Ed25519.Field51.linv", "Spec.Ed25519.PointOps.to_aff_point", "Hacl.Impl.Ed25519.Field51.refl_ext_point", "Hacl.Impl.Ed25519.Group.a_spec" ]
[]
module Hacl.Impl.Ed25519.Group module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 open Hacl.Impl.Ed25519.PointConstants module LSeq = Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module BE = Hacl.Impl.Exponentiation.Definitions module S = Spec.Ed25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let a_spec = S.aff_point_c unfold
false
false
Hacl.Impl.Ed25519.Group.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val refl (a: LSeq.lseq uint64 20 {F51.linv a}) : GTot a_spec
[]
Hacl.Impl.Ed25519.Group.refl
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Group.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Lib.Sequence.lseq Lib.IntTypes.uint64 20 {Hacl.Impl.Ed25519.Field51.linv a} -> Prims.GTot Hacl.Impl.Ed25519.Group.a_spec
{ "end_col": 39, "end_line": 25, "start_col": 2, "start_line": 25 }
Prims.Tot
val point_zero : BE.lone_st U64 20ul 0ul mk_to_ed25519_comm_monoid
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_zero ctx one = make_point_inf one
val point_zero : BE.lone_st U64 20ul 0ul mk_to_ed25519_comm_monoid let point_zero ctx one =
false
null
false
make_point_inf one
{ "checked_file": "Hacl.Impl.Ed25519.Group.fst.checked", "dependencies": [ "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Impl.Ed25519.PointDouble.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.PointAdd.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.Group.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Ed25519.PointConstants.make_point_inf", "Prims.unit" ]
[]
module Hacl.Impl.Ed25519.Group module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 open Hacl.Impl.Ed25519.PointConstants module LSeq = Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module BE = Hacl.Impl.Exponentiation.Definitions module S = Spec.Ed25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let a_spec = S.aff_point_c unfold let refl (a:LSeq.lseq uint64 20{F51.linv a}) : GTot a_spec = S.to_aff_point (F51.refl_ext_point a) unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True inline_for_extraction noextract let mk_to_ed25519_comm_monoid : BE.to_comm_monoid U64 20ul 0ul = { BE.a_spec = a_spec; BE.comm_monoid = S.mk_ed25519_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = F51.linv; BE.refl = refl; } inline_for_extraction noextract val point_add : BE.lmul_st U64 20ul 0ul mk_to_ed25519_comm_monoid let point_add ctx x y xy = let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_add_lemma (F51.refl_ext_point (as_seq h0 x)) (F51.refl_ext_point (as_seq h0 y)); Hacl.Impl.Ed25519.PointAdd.point_add xy x y inline_for_extraction noextract val point_double : BE.lsqr_st U64 20ul 0ul mk_to_ed25519_comm_monoid let point_double ctx x xx = let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_double_lemma (F51.refl_ext_point (as_seq h0 x)); Hacl.Impl.Ed25519.PointDouble.point_double xx x inline_for_extraction noextract
false
false
Hacl.Impl.Ed25519.Group.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_zero : BE.lone_st U64 20ul 0ul mk_to_ed25519_comm_monoid
[]
Hacl.Impl.Ed25519.Group.point_zero
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Group.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Exponentiation.Definitions.lone_st Lib.IntTypes.U64 20ul 0ul Hacl.Impl.Ed25519.Group.mk_to_ed25519_comm_monoid
{ "end_col": 43, "end_line": 59, "start_col": 25, "start_line": 59 }
Prims.Tot
val point_double : BE.lsqr_st U64 20ul 0ul mk_to_ed25519_comm_monoid
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_double ctx x xx = let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_double_lemma (F51.refl_ext_point (as_seq h0 x)); Hacl.Impl.Ed25519.PointDouble.point_double xx x
val point_double : BE.lsqr_st U64 20ul 0ul mk_to_ed25519_comm_monoid let point_double ctx x xx =
false
null
false
let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_double_lemma (F51.refl_ext_point (as_seq h0 x)); Hacl.Impl.Ed25519.PointDouble.point_double xx x
{ "checked_file": "Hacl.Impl.Ed25519.Group.fst.checked", "dependencies": [ "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Impl.Ed25519.PointDouble.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.PointAdd.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.Group.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Ed25519.PointDouble.point_double", "Prims.unit", "Spec.Ed25519.Lemmas.to_aff_point_double_lemma", "Hacl.Impl.Ed25519.Field51.refl_ext_point", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module Hacl.Impl.Ed25519.Group module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 open Hacl.Impl.Ed25519.PointConstants module LSeq = Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module BE = Hacl.Impl.Exponentiation.Definitions module S = Spec.Ed25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let a_spec = S.aff_point_c unfold let refl (a:LSeq.lseq uint64 20{F51.linv a}) : GTot a_spec = S.to_aff_point (F51.refl_ext_point a) unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True inline_for_extraction noextract let mk_to_ed25519_comm_monoid : BE.to_comm_monoid U64 20ul 0ul = { BE.a_spec = a_spec; BE.comm_monoid = S.mk_ed25519_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = F51.linv; BE.refl = refl; } inline_for_extraction noextract val point_add : BE.lmul_st U64 20ul 0ul mk_to_ed25519_comm_monoid let point_add ctx x y xy = let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_add_lemma (F51.refl_ext_point (as_seq h0 x)) (F51.refl_ext_point (as_seq h0 y)); Hacl.Impl.Ed25519.PointAdd.point_add xy x y inline_for_extraction noextract
false
false
Hacl.Impl.Ed25519.Group.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_double : BE.lsqr_st U64 20ul 0ul mk_to_ed25519_comm_monoid
[]
Hacl.Impl.Ed25519.Group.point_double
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Group.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Exponentiation.Definitions.lsqr_st Lib.IntTypes.U64 20ul 0ul Hacl.Impl.Ed25519.Group.mk_to_ed25519_comm_monoid
{ "end_col": 49, "end_line": 54, "start_col": 27, "start_line": 51 }
Prims.Tot
val point_add : BE.lmul_st U64 20ul 0ul mk_to_ed25519_comm_monoid
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_add ctx x y xy = let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_add_lemma (F51.refl_ext_point (as_seq h0 x)) (F51.refl_ext_point (as_seq h0 y)); Hacl.Impl.Ed25519.PointAdd.point_add xy x y
val point_add : BE.lmul_st U64 20ul 0ul mk_to_ed25519_comm_monoid let point_add ctx x y xy =
false
null
false
let h0 = ST.get () in Spec.Ed25519.Lemmas.to_aff_point_add_lemma (F51.refl_ext_point (as_seq h0 x)) (F51.refl_ext_point (as_seq h0 y)); Hacl.Impl.Ed25519.PointAdd.point_add xy x y
{ "checked_file": "Hacl.Impl.Ed25519.Group.fst.checked", "dependencies": [ "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Impl.Ed25519.PointDouble.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.PointAdd.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.Group.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Ed25519.PointAdd.point_add", "Prims.unit", "Spec.Ed25519.Lemmas.to_aff_point_add_lemma", "Hacl.Impl.Ed25519.Field51.refl_ext_point", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module Hacl.Impl.Ed25519.Group module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 open Hacl.Impl.Ed25519.PointConstants module LSeq = Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module BE = Hacl.Impl.Exponentiation.Definitions module S = Spec.Ed25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let a_spec = S.aff_point_c unfold let refl (a:LSeq.lseq uint64 20{F51.linv a}) : GTot a_spec = S.to_aff_point (F51.refl_ext_point a) unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True inline_for_extraction noextract let mk_to_ed25519_comm_monoid : BE.to_comm_monoid U64 20ul 0ul = { BE.a_spec = a_spec; BE.comm_monoid = S.mk_ed25519_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = F51.linv; BE.refl = refl; } inline_for_extraction noextract
false
false
Hacl.Impl.Ed25519.Group.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_add : BE.lmul_st U64 20ul 0ul mk_to_ed25519_comm_monoid
[]
Hacl.Impl.Ed25519.Group.point_add
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Group.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Exponentiation.Definitions.lmul_st Lib.IntTypes.U64 20ul 0ul Hacl.Impl.Ed25519.Group.mk_to_ed25519_comm_monoid
{ "end_col": 45, "end_line": 46, "start_col": 26, "start_line": 42 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mmref (a:Type) = mmmref a (Heap.trivial_preorder a)
let mmref (a: Type) =
false
null
false
mmmref a (Heap.trivial_preorder a)
{ "checked_file": "FStar.HyperStack.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "FStar.HyperStack.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mmmref", "FStar.Heap.trivial_preorder" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.HyperStack include FStar.Monotonic.HyperStack type reference (a:Type) = mreference a (Heap.trivial_preorder a) let stackref (a:Type) = mstackref a (Heap.trivial_preorder a) let ref (a:Type) = mref a (Heap.trivial_preorder a)
false
true
FStar.HyperStack.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mmref : a: Type0 -> Type0
[]
FStar.HyperStack.mmref
{ "file_name": "ulib/FStar.HyperStack.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Type0 -> Type0
{ "end_col": 55, "end_line": 26, "start_col": 21, "start_line": 26 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ref (a:Type) = mref a (Heap.trivial_preorder a)
let ref (a: Type) =
false
null
false
mref a (Heap.trivial_preorder a)
{ "checked_file": "FStar.HyperStack.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "FStar.HyperStack.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mref", "FStar.Heap.trivial_preorder" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.HyperStack include FStar.Monotonic.HyperStack type reference (a:Type) = mreference a (Heap.trivial_preorder a)
false
true
FStar.HyperStack.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ref : a: Type0 -> Type0
[]
FStar.HyperStack.ref
{ "file_name": "ulib/FStar.HyperStack.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Type0 -> Type0
{ "end_col": 51, "end_line": 23, "start_col": 19, "start_line": 23 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mmstackref (a:Type) = mmmstackref a (Heap.trivial_preorder a)
let mmstackref (a: Type) =
false
null
false
mmmstackref a (Heap.trivial_preorder a)
{ "checked_file": "FStar.HyperStack.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "FStar.HyperStack.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mmmstackref", "FStar.Heap.trivial_preorder" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.HyperStack include FStar.Monotonic.HyperStack type reference (a:Type) = mreference a (Heap.trivial_preorder a) let stackref (a:Type) = mstackref a (Heap.trivial_preorder a) let ref (a:Type) = mref a (Heap.trivial_preorder a)
false
true
FStar.HyperStack.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mmstackref : a: Type0 -> Type0
[]
FStar.HyperStack.mmstackref
{ "file_name": "ulib/FStar.HyperStack.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Type0 -> Type0
{ "end_col": 65, "end_line": 25, "start_col": 26, "start_line": 25 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let stackref (a:Type) = mstackref a (Heap.trivial_preorder a)
let stackref (a: Type) =
false
null
false
mstackref a (Heap.trivial_preorder a)
{ "checked_file": "FStar.HyperStack.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "FStar.HyperStack.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mstackref", "FStar.Heap.trivial_preorder" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.HyperStack include FStar.Monotonic.HyperStack type reference (a:Type) = mreference a (Heap.trivial_preorder a)
false
true
FStar.HyperStack.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val stackref : a: Type0 -> Type0
[]
FStar.HyperStack.stackref
{ "file_name": "ulib/FStar.HyperStack.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Type0 -> Type0
{ "end_col": 61, "end_line": 22, "start_col": 24, "start_line": 22 }
FStar.Pervasives.Lemma
val reference_distinct_sel_disjoint (#a: Type0) (h: mem) (r1 r2: reference a) : Lemma (requires (h `contains` r1 /\ h `contains` r2 /\ frameOf r1 == frameOf r2 /\ as_addr r1 == as_addr r2) ) (ensures (sel h r1 == sel h r2))
[ { "abbrev": false, "full_module": "FStar.Monotonic.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let reference_distinct_sel_disjoint (#a:Type0) (h: mem) (r1: reference a) (r2: reference a) : Lemma (requires ( h `contains` r1 /\ h `contains` r2 /\ frameOf r1 == frameOf r2 /\ as_addr r1 == as_addr r2 )) (ensures ( sel h r1 == sel h r2 )) = mreference_distinct_sel_disjoint h r1 r2
val reference_distinct_sel_disjoint (#a: Type0) (h: mem) (r1 r2: reference a) : Lemma (requires (h `contains` r1 /\ h `contains` r2 /\ frameOf r1 == frameOf r2 /\ as_addr r1 == as_addr r2) ) (ensures (sel h r1 == sel h r2)) let reference_distinct_sel_disjoint (#a: Type0) (h: mem) (r1 r2: reference a) : Lemma (requires (h `contains` r1 /\ h `contains` r2 /\ frameOf r1 == frameOf r2 /\ as_addr r1 == as_addr r2) ) (ensures (sel h r1 == sel h r2)) =
false
null
true
mreference_distinct_sel_disjoint h r1 r2
{ "checked_file": "FStar.HyperStack.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.HyperStack.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "FStar.HyperStack.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.reference", "FStar.Monotonic.HyperStack.mreference_distinct_sel_disjoint", "FStar.Heap.trivial_preorder", "Prims.unit", "Prims.l_and", "FStar.Monotonic.HyperStack.contains", "Prims.eq2", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperStack.frameOf", "Prims.pos", "FStar.Monotonic.HyperStack.as_addr", "Prims.squash", "FStar.Monotonic.HyperStack.sel", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.HyperStack include FStar.Monotonic.HyperStack type reference (a:Type) = mreference a (Heap.trivial_preorder a) let stackref (a:Type) = mstackref a (Heap.trivial_preorder a) let ref (a:Type) = mref a (Heap.trivial_preorder a) let mmstackref (a:Type) = mmmstackref a (Heap.trivial_preorder a) let mmref (a:Type) = mmmref a (Heap.trivial_preorder a) type s_ref (i:rid) (a:Type) = s_mref i a (Heap.trivial_preorder a) (* Two references with different reads are disjoint. *) let reference_distinct_sel_disjoint (#a:Type0) (h: mem) (r1: reference a) (r2: reference a) : Lemma (requires ( h `contains` r1 /\ h `contains` r2 /\ frameOf r1 == frameOf r2 /\ as_addr r1 == as_addr r2 )) (ensures ( sel h r1 == sel h r2
false
false
FStar.HyperStack.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val reference_distinct_sel_disjoint (#a: Type0) (h: mem) (r1 r2: reference a) : Lemma (requires (h `contains` r1 /\ h `contains` r2 /\ frameOf r1 == frameOf r2 /\ as_addr r1 == as_addr r2) ) (ensures (sel h r1 == sel h r2))
[]
FStar.HyperStack.reference_distinct_sel_disjoint
{ "file_name": "ulib/FStar.HyperStack.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
h: FStar.Monotonic.HyperStack.mem -> r1: FStar.HyperStack.reference a -> r2: FStar.HyperStack.reference a -> FStar.Pervasives.Lemma (requires FStar.Monotonic.HyperStack.contains h r1 /\ FStar.Monotonic.HyperStack.contains h r2 /\ FStar.Monotonic.HyperStack.frameOf r1 == FStar.Monotonic.HyperStack.frameOf r2 /\ FStar.Monotonic.HyperStack.as_addr r1 == FStar.Monotonic.HyperStack.as_addr r2) (ensures FStar.Monotonic.HyperStack.sel h r1 == FStar.Monotonic.HyperStack.sel h r2)
{ "end_col": 42, "end_line": 43, "start_col": 2, "start_line": 43 }
Prims.GTot
val synth_case_recip' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: (k: enum_key e -> x: refine_with_tag tag_of_data k -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x
val synth_case_recip' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: (k: enum_key e -> x: refine_with_tag tag_of_data k -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) let synth_case_recip' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: (k: enum_key e -> x: refine_with_tag tag_of_data k -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) =
false
null
false
synth_case_recip (tag_of_data x) x
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "sometrivial" ]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Base.refine_with_tag" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_case_recip' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: (k: enum_key e -> x: refine_with_tag tag_of_data k -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x))
[]
LowParse.Spec.Sum.synth_case_recip'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: LowParse.Spec.Enum.enum key repr -> tag_of_data: (_: data -> LowParse.Spec.Enum.enum_key e) -> type_of_tag: (_: LowParse.Spec.Enum.enum_key e -> Type) -> synth_case_recip: (k: LowParse.Spec.Enum.enum_key e -> x: LowParse.Spec.Base.refine_with_tag tag_of_data k -> type_of_tag k) -> x: data -> Prims.GTot (type_of_tag (tag_of_data x))
{ "end_col": 36, "end_line": 16, "start_col": 2, "start_line": 16 }
Prims.Tot
val sum_key_type (t: sum) : Tot eqtype
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key
val sum_key_type (t: sum) : Tot eqtype let sum_key_type (t: sum) : Tot eqtype =
false
null
false
match t with | Sum key _ _ _ _ _ _ _ _ _ -> key
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.sum", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Base.refine_with_tag", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "LowParse.Spec.Sum.synth_case_recip'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction
false
true
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sum_key_type (t: sum) : Tot eqtype
[]
LowParse.Spec.Sum.sum_key_type
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.sum -> Prims.eqtype
{ "end_col": 49, "end_line": 44, "start_col": 2, "start_line": 44 }
Prims.Tot
val parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc)
val parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) =
false
null
false
parse_sum' t p (parse_sum_cases t pc)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "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.Spec.Sum.parse_sum'", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.parse_sum_cases", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.sum_type" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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))))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t))
[]
LowParse.Spec.Sum.parse_sum
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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.Spec.Base.parser (LowParse.Spec.Sum.parse_sum_kind kt t pc) (LowParse.Spec.Sum.sum_type t)
{ "end_col": 39, "end_line": 174, "start_col": 2, "start_line": 174 }
Prims.Tot
val parse_sum_cases' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x
val parse_sum_cases' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) let parse_sum_cases' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) =
false
null
false
synth_sum_case_injective s x; (dsnd (f x)) `parse_synth` (synth_sum_case s x)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "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.Combinators.parse_synth", "Prims.__proj__Mkdtuple2__item___1", "LowParse.Spec.Sum.sum_cases", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.synth_sum_case", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_injective", "FStar.Pervasives.dfst" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_sum_cases' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x))
[]
LowParse.Spec.Sum.parse_sum_cases'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.sum -> f: (x: LowParse.Spec.Sum.sum_key s -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag s x))) -> x: LowParse.Spec.Sum.sum_key s -> LowParse.Spec.Base.parser (FStar.Pervasives.dfst (f x)) (LowParse.Spec.Sum.sum_cases s x)
{ "end_col": 45, "end_line": 131, "start_col": 2, "start_line": 130 }
Prims.Tot
val dsum_repr_type (t: dsum) : Tot eqtype
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr
val dsum_repr_type (t: dsum) : Tot eqtype let dsum_repr_type (t: dsum) : Tot eqtype =
false
null
false
match t with | DSum _ repr _ _ _ _ _ _ _ _ _ -> repr
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.dsum", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_type_of_tag'", "LowParse.Spec.Base.refine_with_tag", "Prims.squash", "Prims.eq2" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction
false
true
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val dsum_repr_type (t: dsum) : Tot eqtype
[]
LowParse.Spec.Sum.dsum_repr_type
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> Prims.eqtype
{ "end_col": 54, "end_line": 494, "start_col": 2, "start_line": 494 }
Prims.Tot
val weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (#k': parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k'
val weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (#k': parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (#k': parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind =
false
null
false
weaken_parse_dsum_cases_kind s f k'
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "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.weaken_parse_dsum_cases_kind" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (#k': parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind
[]
LowParse.Spec.Sum.weaken_parse_dsum_cases_kind'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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))) -> p: LowParse.Spec.Base.parser k' (LowParse.Spec.Sum.dsum_type_of_unknown_tag s) -> LowParse.Spec.Base.parser_kind
{ "end_col": 37, "end_line": 560, "start_col": 2, "start_line": 560 }
Prims.GTot
val synth_dsum_case_recip' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |)
val synth_dsum_case_recip' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) let synth_dsum_case_recip' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) =
false
null
false
let tg = tag_of_data y in (| tg, synth_case_recip tg y |)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "sometrivial" ]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.Sum.dsum_type_of_tag'", "Prims.Mkdtuple2", "Prims.dtuple2" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_dsum_case_recip' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)
[]
LowParse.Spec.Sum.synth_dsum_case_recip'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: LowParse.Spec.Enum.enum key repr -> tag_of_data: (_: data -> Prims.GTot (LowParse.Spec.Enum.maybe_enum_key e)) -> type_of_known_tag: (_: LowParse.Spec.Enum.enum_key e -> Type) -> type_of_unknown_tag: Type -> synth_case_recip: (k: LowParse.Spec.Enum.maybe_enum_key e -> _: LowParse.Spec.Base.refine_with_tag tag_of_data k -> LowParse.Spec.Sum.dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k) -> y: data -> Prims.GTot (Prims.dtuple2 (LowParse.Spec.Enum.maybe_enum_key e) (fun x -> LowParse.Spec.Sum.dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x))
{ "end_col": 33, "end_line": 459, "start_col": 1, "start_line": 458 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t)
let dsum_type_of_tag (t: dsum) =
false
null
false
dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.dsum", "LowParse.Spec.Sum.dsum_type_of_tag'", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Spec.Enum.maybe_enum_key" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val dsum_type_of_tag : t: LowParse.Spec.Sum.dsum -> k: LowParse.Spec.Enum.maybe_enum_key (LowParse.Spec.Sum.dsum_enum t) -> Type
[]
LowParse.Spec.Sum.dsum_type_of_tag
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> k: LowParse.Spec.Enum.maybe_enum_key (LowParse.Spec.Sum.dsum_enum t) -> Type
{ "end_col": 89, "end_line": 540, "start_col": 2, "start_line": 540 }
Prims.Tot
val parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: (x: dsum_key t -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc
val parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: (x: dsum_key t -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: (x: dsum_key t -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) =
false
null
false
parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_key", "LowParse.Spec.Sum.dsum_cases", "LowParse.Spec.Combinators.parse_tagged_union", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_tag_of_data", "LowParse.Spec.Combinators.and_then_kind" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: (x: dsum_key t -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t))
[]
LowParse.Spec.Sum.parse_dsum'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) -> pc: (x: LowParse.Spec.Sum.dsum_key t -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_cases t x)) -> LowParse.Spec.Base.parser (LowParse.Spec.Combinators.and_then_kind kt k) (LowParse.Spec.Sum.dsum_type t)
{ "end_col": 6, "end_line": 691, "start_col": 2, "start_line": 684 }
Prims.Tot
val parse_dsum_cases_kind (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 parser_kind
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k
val parse_dsum_cases_kind (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 parser_kind let parse_dsum_cases_kind (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 parser_kind =
false
null
false
match x with | Known k -> dfst (f k) | _ -> k
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "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.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_enum", "FStar.Pervasives.dfst", "LowParse.Spec.Enum.maybe_enum_key" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_cases_kind (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 parser_kind
[]
LowParse.Spec.Sum.parse_dsum_cases_kind
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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 -> LowParse.Spec.Base.parser_kind
{ "end_col": 10, "end_line": 634, "start_col": 2, "start_line": 632 }
Prims.Tot
val parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (k: parser_kind) : Tot parser_kind
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k)
val parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (k: parser_kind) : Tot parser_kind let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (k: parser_kind) : Tot parser_kind =
false
null
false
and_then_kind kt (weaken_parse_dsum_cases_kind s f k)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (k: parser_kind) : Tot parser_kind
[]
LowParse.Spec.Sum.parse_dsum_kind
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
kt: LowParse.Spec.Base.parser_kind -> 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))) -> k: LowParse.Spec.Base.parser_kind -> LowParse.Spec.Base.parser_kind
{ "end_col": 55, "end_line": 700, "start_col": 2, "start_line": 700 }
Prims.Tot
val parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g)
val parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) =
false
null
false
parse_dsum' t p (parse_dsum_cases t f g)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Spec.Sum.parse_dsum'", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Sum.parse_dsum_cases", "LowParse.Spec.Sum.parse_dsum_kind", "LowParse.Spec.Sum.dsum_type" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t))
[]
LowParse.Spec.Sum.parse_dsum
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) -> f: (x: LowParse.Spec.Sum.dsum_known_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) -> g: LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) -> LowParse.Spec.Base.parser (LowParse.Spec.Sum.parse_dsum_kind kt t f k) (LowParse.Spec.Sum.dsum_type t)
{ "end_col": 42, "end_line": 710, "start_col": 2, "start_line": 710 }
Prims.Tot
val sum_repr_type (t: sum) : Tot eqtype
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr
val sum_repr_type (t: sum) : Tot eqtype let sum_repr_type (t: sum) : Tot eqtype =
false
null
false
match t with | Sum _ repr _ _ _ _ _ _ _ _ -> repr
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.sum", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Base.refine_with_tag", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "LowParse.Spec.Sum.synth_case_recip'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction
false
true
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sum_repr_type (t: sum) : Tot eqtype
[]
LowParse.Spec.Sum.sum_repr_type
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.sum -> Prims.eqtype
{ "end_col": 51, "end_line": 48, "start_col": 2, "start_line": 48 }
Prims.Tot
val parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: (x: sum_key t -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc
val parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: (x: sum_key t -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: (x: sum_key t -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) =
false
null
false
parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Sum.sum_key", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Combinators.parse_tagged_union", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.sum_tag_of_data", "LowParse.Spec.Combinators.and_then_kind" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: (x: sum_key t -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t))
[]
LowParse.Spec.Sum.parse_sum'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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 -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_cases t x)) -> LowParse.Spec.Base.parser (LowParse.Spec.Combinators.and_then_kind (LowParse.Spec.Combinators.parse_filter_kind kt) k) (LowParse.Spec.Sum.sum_type t)
{ "end_col": 6, "end_line": 158, "start_col": 2, "start_line": 151 }
Prims.Tot
val parse_sum_kind (kt: parser_kind) (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc)
val parse_sum_kind (kt: parser_kind) (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind let parse_sum_kind (kt: parser_kind) (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind =
false
null
false
and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Sum.weaken_parse_cases_kind" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_sum_kind (kt: parser_kind) (t: sum) (pc: (x: sum_key t -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind
[]
LowParse.Spec.Sum.parse_sum_kind
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
kt: LowParse.Spec.Base.parser_kind -> 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))) -> LowParse.Spec.Base.parser_kind
{ "end_col": 69, "end_line": 166, "start_col": 2, "start_line": 166 }
Prims.Tot
val dsum_key_type (t: dsum) : Tot eqtype
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key
val dsum_key_type (t: dsum) : Tot eqtype let dsum_key_type (t: dsum) : Tot eqtype =
false
null
false
match t with | DSum key _ _ _ _ _ _ _ _ _ _ -> key
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.dsum", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_type_of_tag'", "LowParse.Spec.Base.refine_with_tag", "Prims.squash", "Prims.eq2" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction
false
true
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val dsum_key_type (t: dsum) : Tot eqtype
[]
LowParse.Spec.Sum.dsum_key_type
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> Prims.eqtype
{ "end_col": 52, "end_line": 490, "start_col": 2, "start_line": 490 }
Prims.Tot
val serialize_sum_cases' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (sr: (x: sum_key s -> Tot (serializer (dsnd (f x))))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () )
val serialize_sum_cases' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (sr: (x: sum_key s -> Tot (serializer (dsnd (f x))))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) let serialize_sum_cases' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (sr: (x: sum_key s -> Tot (serializer (dsnd (f x))))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) =
false
null
false
synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) ())
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "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.Spec.Combinators.serialize_synth", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Sum.synth_sum_case", "LowParse.Spec.Sum.synth_sum_case_recip", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_inverse", "LowParse.Spec.Sum.synth_sum_case_injective", "FStar.Pervasives.dfst", "LowParse.Spec.Sum.parse_sum_cases'" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_sum_cases' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (sr: (x: sum_key s -> Tot (serializer (dsnd (f x))))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x))
[]
LowParse.Spec.Sum.serialize_sum_cases'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.sum -> f: (x: LowParse.Spec.Sum.sum_key s -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag s x))) -> sr: (x: LowParse.Spec.Sum.sum_key s -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x)) ) -> x: LowParse.Spec.Sum.sum_key s -> LowParse.Spec.Base.serializer (LowParse.Spec.Sum.parse_sum_cases' s f x)
{ "end_col": 5, "end_line": 280, "start_col": 2, "start_line": 272 }
Prims.Tot
val sum_tag_of_data (t: sum) : Tot (x: sum_type t -> Tot (sum_key t))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data
val sum_tag_of_data (t: sum) : Tot (x: sum_type t -> Tot (sum_key t)) let sum_tag_of_data (t: sum) : Tot (x: sum_type t -> Tot (sum_key t)) =
false
null
false
match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.sum", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Base.refine_with_tag", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "LowParse.Spec.Sum.synth_case_recip'", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.sum_key" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sum_tag_of_data (t: sum) : Tot (x: sum_type t -> Tot (sum_key t))
[]
LowParse.Spec.Sum.sum_tag_of_data
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.sum -> x: LowParse.Spec.Sum.sum_type t -> LowParse.Spec.Sum.sum_key t
{ "end_col": 52, "end_line": 72, "start_col": 2, "start_line": 71 }
Prims.Tot
val sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e
val sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) =
false
null
false
match t with | Sum _ _ e _ _ _ _ _ _ _ -> e
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.sum", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Base.refine_with_tag", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "LowParse.Spec.Sum.synth_case_recip'", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_repr_type" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t))
[]
LowParse.Spec.Sum.sum_enum
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.sum -> LowParse.Spec.Enum.enum (LowParse.Spec.Sum.sum_key_type t) (LowParse.Spec.Sum.sum_repr_type t)
{ "end_col": 45, "end_line": 52, "start_col": 2, "start_line": 52 }
Prims.Tot
val synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k)
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x
val synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) =
false
null
false
match s with | Sum _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip k x
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "LowParse.Spec.Sum.sum_cases", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Base.refine_with_tag", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "LowParse.Spec.Sum.synth_case_recip'", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.Spec.Sum.sum_type_of_tag" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k)
[]
LowParse.Spec.Sum.synth_sum_case_recip
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.sum -> k: LowParse.Spec.Sum.sum_key s -> x: LowParse.Spec.Sum.sum_cases s k -> LowParse.Spec.Sum.sum_type_of_tag s k
{ "end_col": 22, "end_line": 260, "start_col": 2, "start_line": 259 }
Prims.Tot
val serialize_sum_cases (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (sr: (x: sum_key s -> Tot (serializer (dsnd (f x))))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x)
val serialize_sum_cases (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (sr: (x: sum_key s -> Tot (serializer (dsnd (f x))))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) let serialize_sum_cases (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (sr: (x: sum_key s -> Tot (serializer (dsnd (f x))))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) =
false
null
false
Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "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.Spec.Base.serialize_ext", "FStar.Pervasives.dfst", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Sum.parse_sum_cases'", "LowParse.Spec.Sum.serialize_sum_cases'", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.parse_sum_cases", "Prims.unit", "FStar.Classical.forall_intro", "LowParse.Bytes.bytes", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_sum_cases_eq'" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_sum_cases (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (sr: (x: sum_key s -> Tot (serializer (dsnd (f x))))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x))
[]
LowParse.Spec.Sum.serialize_sum_cases
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.sum -> f: (x: LowParse.Spec.Sum.sum_key s -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag s x))) -> sr: (x: LowParse.Spec.Sum.sum_key s -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x)) ) -> x: LowParse.Spec.Sum.sum_key s -> LowParse.Spec.Base.serializer (LowParse.Spec.Sum.parse_sum_cases s f x)
{ "end_col": 27, "end_line": 292, "start_col": 2, "start_line": 288 }
FStar.Pervasives.Lemma
val synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s)
val synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) =
false
null
true
Classical.forall_intro (Sum?.synth_case_synth_case_recip s)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "FStar.Classical.forall_intro", "LowParse.Spec.Sum.__proj__Sum__item__data", "Prims.eq2", "LowParse.Spec.Sum.__proj__Sum__item__synth_case", "LowParse.Spec.Sum.__proj__Sum__item__tag_of_data", "LowParse.Spec.Sum.synth_case_recip'", "LowParse.Spec.Sum.__proj__Sum__item__key", "LowParse.Spec.Sum.__proj__Sum__item__repr", "LowParse.Spec.Sum.__proj__Sum__item__e", "LowParse.Spec.Sum.__proj__Sum__item__type_of_tag", "LowParse.Spec.Sum.__proj__Sum__item__synth_case_recip", "LowParse.Spec.Sum.__proj__Sum__item__synth_case_synth_case_recip", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_inverse", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Sum.synth_sum_case", "LowParse.Spec.Sum.synth_sum_case_recip", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k))
[]
LowParse.Spec.Sum.synth_sum_case_inverse
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.sum -> k: LowParse.Spec.Sum.sum_key s -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_inverse (LowParse.Spec.Sum.synth_sum_case s k) (LowParse.Spec.Sum.synth_sum_case_recip s k))
{ "end_col": 61, "end_line": 264, "start_col": 2, "start_line": 264 }
Prims.Pure
val serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: (x: sum_key t -> Tot (parser k (sum_cases t x)))) (sc: (x: sum_key t -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc
val serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: (x: sum_key t -> Tot (parser k (sum_cases t x)))) (sc: (x: sum_key t -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: (x: sum_key t -> Tot (parser k (sum_cases t x)))) (sc: (x: sum_key t -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) =
false
null
false
serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Base.serializer", "LowParse.Spec.Sum.sum_key", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Combinators.serialize_tagged_union", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Spec.Enum.serialize_enum_key", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.sum_tag_of_data", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.Sum.parse_sum'", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.l_True" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: (x: sum_key t -> Tot (parser k (sum_cases t x)))) (sc: (x: sum_key t -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True))
[]
LowParse.Spec.Sum.serialize_sum'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.sum -> s: LowParse.Spec.Base.serializer p -> sc: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Spec.Base.serializer (pc x)) -> Prims.Pure (LowParse.Spec.Base.serializer (LowParse.Spec.Sum.parse_sum' t p pc))
{ "end_col": 6, "end_line": 314, "start_col": 2, "start_line": 305 }
Prims.GTot
val synth_dsum_case' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: (x: enum_key e -> y: type_of_known_tag x -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: (x: unknown_enum_repr e -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y
val synth_dsum_case' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: (x: enum_key e -> y: type_of_known_tag x -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: (x: unknown_enum_repr e -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data let synth_dsum_case' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: (x: enum_key e -> y: type_of_known_tag x -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: (x: unknown_enum_repr e -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data =
false
null
false
let (| x , y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "sometrivial" ]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.Enum.Known", "LowParse.Spec.Enum.unknown_enum_repr", "LowParse.Spec.Enum.Unknown", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_tag'" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_dsum_case' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: (x: enum_key e -> y: type_of_known_tag x -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: (x: unknown_enum_repr e -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data
[]
LowParse.Spec.Sum.synth_dsum_case'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: LowParse.Spec.Enum.enum key repr -> tag_of_data: (_: data -> Prims.GTot (LowParse.Spec.Enum.maybe_enum_key e)) -> type_of_known_tag: (_: LowParse.Spec.Enum.enum_key e -> Type) -> type_of_unknown_tag: Type -> synth_known_case: (x: LowParse.Spec.Enum.enum_key e -> y: type_of_known_tag x -> LowParse.Spec.Base.refine_with_tag tag_of_data (LowParse.Spec.Enum.Known x)) -> synth_unknown_case: (x: LowParse.Spec.Enum.unknown_enum_repr e -> _: type_of_unknown_tag -> LowParse.Spec.Base.refine_with_tag tag_of_data (LowParse.Spec.Enum.Unknown x)) -> xy: Prims.dtuple2 (LowParse.Spec.Enum.maybe_enum_key e) (fun x -> LowParse.Spec.Sum.dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Prims.GTot data
{ "end_col": 35, "end_line": 445, "start_col": 1, "start_line": 442 }
Prims.Tot
val synth_dsum_case (s: dsum) : Tot (x: dsum_key s -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case
val synth_dsum_case (s: dsum) : Tot (x: dsum_key s -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) let synth_dsum_case (s: dsum) : Tot (x: dsum_key s -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) =
false
null
false
match s with | DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.dsum", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_type_of_tag'", "LowParse.Spec.Base.refine_with_tag", "Prims.squash", "Prims.eq2", "LowParse.Spec.Sum.dsum_key", "LowParse.Spec.Sum.dsum_type_of_tag", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_tag_of_data" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_dsum_case (s: dsum) : Tot (x: dsum_key s -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x))
[]
LowParse.Spec.Sum.synth_dsum_case
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.dsum -> x: LowParse.Spec.Sum.dsum_key s -> _: LowParse.Spec.Sum.dsum_type_of_tag s x -> LowParse.Spec.Base.refine_with_tag (LowParse.Spec.Sum.dsum_tag_of_data s) x
{ "end_col": 64, "end_line": 566, "start_col": 2, "start_line": 566 }
Prims.Tot
val parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x
val parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) =
false
null
false
synth_dsum_case_injective s x; (parse_dsum_type_of_tag s f g x) `parse_synth` (synth_dsum_case s x)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "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.Spec.Combinators.parse_synth", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Sum.dsum_type_of_tag", "LowParse.Spec.Sum.dsum_cases", "LowParse.Spec.Sum.parse_dsum_type_of_tag", "LowParse.Spec.Sum.synth_dsum_case", "Prims.unit", "LowParse.Spec.Sum.synth_dsum_case_injective" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x))
[]
LowParse.Spec.Sum.parse_dsum_cases
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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 -> LowParse.Spec.Base.parser (LowParse.Spec.Sum.weaken_parse_dsum_cases_kind s f k) (LowParse.Spec.Sum.dsum_cases s x)
{ "end_col": 66, "end_line": 623, "start_col": 2, "start_line": 622 }
Prims.Tot
val synth_dsum_case_recip (s: dsum) : Tot (x: dsum_key s -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip
val synth_dsum_case_recip (s: dsum) : Tot (x: dsum_key s -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) let synth_dsum_case_recip (s: dsum) : Tot (x: dsum_key s -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) =
false
null
false
match s with | DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.dsum", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_type_of_tag'", "LowParse.Spec.Base.refine_with_tag", "Prims.squash", "Prims.eq2", "LowParse.Spec.Sum.dsum_key", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_tag_of_data", "LowParse.Spec.Sum.dsum_type_of_tag" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_dsum_case_recip (s: dsum) : Tot (x: dsum_key s -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x))
[]
LowParse.Spec.Sum.synth_dsum_case_recip
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.dsum -> x: LowParse.Spec.Sum.dsum_key s -> _: LowParse.Spec.Base.refine_with_tag (LowParse.Spec.Sum.dsum_tag_of_data s) x -> LowParse.Spec.Sum.dsum_type_of_tag s x
{ "end_col": 76, "end_line": 572, "start_col": 2, "start_line": 572 }
Prims.Tot
val dsum_tag_of_data (t: dsum) : Tot (x: dsum_type t -> Tot (dsum_key t))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data
val dsum_tag_of_data (t: dsum) : Tot (x: dsum_type t -> Tot (dsum_key t)) let dsum_tag_of_data (t: dsum) : Tot (x: dsum_type t -> Tot (dsum_key t)) =
false
null
false
match t with | DSum _ _ _ _ tag_of_data _ _ _ _ _ _ -> tag_of_data
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.dsum", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_type_of_tag'", "LowParse.Spec.Base.refine_with_tag", "Prims.squash", "Prims.eq2", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_key" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val dsum_tag_of_data (t: dsum) : Tot (x: dsum_type t -> Tot (dsum_key t))
[]
LowParse.Spec.Sum.dsum_tag_of_data
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> x: LowParse.Spec.Sum.dsum_type t -> LowParse.Spec.Sum.dsum_key t
{ "end_col": 68, "end_line": 522, "start_col": 2, "start_line": 522 }
Prims.GTot
val synth_dsum_case_recip_synth_case_known_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: (x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: key) : GTot Type0
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_dsum_case_recip_synth_case_known_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_known_tag x) . {:pattern (synth_case_recip (Known x) (synth_case (Known x) y))} synth_case_recip (Known x) (synth_case (Known x) y) == y )
val synth_dsum_case_recip_synth_case_known_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: (x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: key) : GTot Type0 let synth_dsum_case_recip_synth_case_known_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: (x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: key) : GTot Type0 =
false
null
false
list_mem x (list_map fst e) ==> (forall (y: type_of_known_tag x). {:pattern (synth_case_recip (Known x) (synth_case (Known x) y))} synth_case_recip (Known x) (synth_case (Known x) y) == y)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "sometrivial" ]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_type_of_tag'", "LowParse.Spec.Base.refine_with_tag", "Prims.l_imp", "Prims.b2t", "LowParse.Spec.Enum.list_mem", "LowParse.Spec.Enum.list_map", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.fst", "Prims.l_Forall", "Prims.eq2", "LowParse.Spec.Enum.Known" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end )) = parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; begin match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k end let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x)) = let f (y: refine_with_tag (dsum_tag_of_data s) (x)) : Lemma (synth_dsum_case s x (synth_dsum_case_recip s x y) == y) = DSum?.synth_case_synth_case_recip s y in Classical.forall_intro f let serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x)) = match x with | Known x' -> serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x) | Unknown x' -> serialize_ext g sg (parse_dsum_type_of_tag s f g x) let serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_cases s f g x)) = synth_dsum_case_injective s x; synth_dsum_case_inverse s x; serialize_synth _ (synth_dsum_case s x) (serialize_dsum_type_of_tag s f sr g sg x) (synth_dsum_case_recip s x) () let serialize_dsum' (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) (sc: ((x: dsum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_dsum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(kt) #(dsum_key t) #(parse_maybe_enum_key p (dsum_enum t)) (serialize_maybe_enum_key p s (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k #pc sc let serialize_dsum (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) : Pure (serializer (parse_dsum s pt f g)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_dsum' s st #_ #(parse_dsum_cases s f g) (serialize_dsum_cases s f sr g sg) let synth_dsum_case_recip_synth_case_known_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: key) : GTot Type0
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_dsum_case_recip_synth_case_known_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: (x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: key) : GTot Type0
[]
LowParse.Spec.Sum.synth_dsum_case_recip_synth_case_known_post
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: LowParse.Spec.Enum.enum key repr -> tag_of_data: (_: data -> LowParse.Spec.Enum.maybe_enum_key e) -> type_of_known_tag: (_: LowParse.Spec.Enum.enum_key e -> Type) -> type_of_unknown_tag: Type -> synth_case: ( x: LowParse.Spec.Enum.maybe_enum_key e -> y: LowParse.Spec.Sum.dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x -> LowParse.Spec.Base.refine_with_tag tag_of_data x) -> synth_case_recip: (k: LowParse.Spec.Enum.maybe_enum_key e -> _: LowParse.Spec.Base.refine_with_tag tag_of_data k -> LowParse.Spec.Sum.dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k) -> x: key -> Prims.GTot Type0
{ "end_col": 3, "end_line": 938, "start_col": 2, "start_line": 935 }
FStar.Pervasives.Lemma
val parse_sum_cases_eq (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input
val parse_sum_cases_eq (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed))) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed))) =
false
null
true
synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "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.Bytes.bytes", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Base.weaken", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.synth_sum_case", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_injective", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_sum_cases", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_sum_cases_eq (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed)))
[]
LowParse.Spec.Sum.parse_sum_cases_eq
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.sum -> f: (x: LowParse.Spec.Sum.sum_key s -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag s x))) -> x: LowParse.Spec.Sum.sum_key s -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_sum_cases s f x) input == (match LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (f x)) input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y consumed) -> FStar.Pervasives.Native.Some (LowParse.Spec.Sum.synth_sum_case s x y, consumed)))
{ "end_col": 95, "end_line": 122, "start_col": 2, "start_line": 121 }
Prims.Tot
val dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e
val dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) =
false
null
false
match t with | DSum _ _ e _ _ _ _ _ _ _ _ -> e
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "LowParse.Spec.Sum.dsum", "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_type_of_tag'", "LowParse.Spec.Base.refine_with_tag", "Prims.squash", "Prims.eq2", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_repr_type" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t))
[]
LowParse.Spec.Sum.dsum_enum
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> LowParse.Spec.Enum.enum (LowParse.Spec.Sum.dsum_key_type t) (LowParse.Spec.Sum.dsum_repr_type t)
{ "end_col": 48, "end_line": 498, "start_col": 2, "start_line": 498 }
Prims.Tot
val serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_cases s f g x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_cases s f g x)) = synth_dsum_case_injective s x; synth_dsum_case_inverse s x; serialize_synth _ (synth_dsum_case s x) (serialize_dsum_type_of_tag s f sr g sg x) (synth_dsum_case_recip s x) ()
val serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_cases s f g x)) let serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_cases s f g x)) =
false
null
false
synth_dsum_case_injective s x; synth_dsum_case_inverse s x; serialize_synth _ (synth_dsum_case s x) (serialize_dsum_type_of_tag s f sr g sg x) (synth_dsum_case_recip s x) ()
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "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.Base.serializer", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Spec.Sum.dsum_key", "LowParse.Spec.Combinators.serialize_synth", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Sum.dsum_type_of_tag", "LowParse.Spec.Sum.dsum_cases", "LowParse.Spec.Sum.parse_dsum_type_of_tag", "LowParse.Spec.Sum.synth_dsum_case", "LowParse.Spec.Sum.serialize_dsum_type_of_tag", "LowParse.Spec.Sum.synth_dsum_case_recip", "Prims.unit", "LowParse.Spec.Sum.synth_dsum_case_inverse", "LowParse.Spec.Sum.synth_dsum_case_injective", "LowParse.Spec.Sum.parse_dsum_cases" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end )) = parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; begin match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k end let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x)) = let f (y: refine_with_tag (dsum_tag_of_data s) (x)) : Lemma (synth_dsum_case s x (synth_dsum_case_recip s x y) == y) = DSum?.synth_case_synth_case_recip s y in Classical.forall_intro f let serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x)) = match x with | Known x' -> serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x) | Unknown x' -> serialize_ext g sg (parse_dsum_type_of_tag s f g x) let serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_cases s f g x))
[]
LowParse.Spec.Sum.serialize_dsum_cases
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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))) -> sr: (x: LowParse.Spec.Sum.dsum_known_key s -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) -> g: LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_unknown_tag s) -> sg: LowParse.Spec.Base.serializer g -> x: LowParse.Spec.Sum.dsum_key s -> LowParse.Spec.Base.serializer (LowParse.Spec.Sum.parse_dsum_cases s f g x)
{ "end_col": 6, "end_line": 884, "start_col": 2, "start_line": 877 }
FStar.Pervasives.Lemma
val synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x)) = let f (y: refine_with_tag (dsum_tag_of_data s) (x)) : Lemma (synth_dsum_case s x (synth_dsum_case_recip s x y) == y) = DSum?.synth_case_synth_case_recip s y in Classical.forall_intro f
val synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x)) let synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x)) =
false
null
true
let f (y: refine_with_tag (dsum_tag_of_data s) (x)) : Lemma (synth_dsum_case s x (synth_dsum_case_recip s x y) == y) = DSum?.synth_case_synth_case_recip s y in Classical.forall_intro f
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Sum.dsum", "LowParse.Spec.Sum.dsum_key", "FStar.Classical.forall_intro", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_tag_of_data", "Prims.eq2", "LowParse.Spec.Sum.synth_dsum_case", "LowParse.Spec.Sum.synth_dsum_case_recip", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.Spec.Sum.__proj__DSum__item__synth_case_synth_case_recip", "LowParse.Spec.Combinators.synth_inverse", "LowParse.Spec.Sum.dsum_type_of_tag" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end )) = parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; begin match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k end let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x))
[]
LowParse.Spec.Sum.synth_dsum_case_inverse
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.dsum -> x: LowParse.Spec.Sum.dsum_key s -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_inverse (LowParse.Spec.Sum.synth_dsum_case s x) (LowParse.Spec.Sum.synth_dsum_case_recip s x))
{ "end_col": 26, "end_line": 851, "start_col": 1, "start_line": 845 }
Prims.Tot
val parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
val parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) =
false
null
false
synth_dsum_case_injective s x; match x with | Known x' -> ((dsnd (f x')) `parse_synth` (synth_dsum_case s (Known x'))) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` (synth_dsum_case s (Unknown x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "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.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Combinators.parse_synth", "Prims.__proj__Mkdtuple2__item___1", "LowParse.Spec.Sum.dsum_cases", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.synth_dsum_case", "LowParse.Spec.Enum.Known", "LowParse.Spec.Sum.parse_dsum_cases_kind", "LowParse.Spec.Enum.unknown_enum_repr", "LowParse.Spec.Enum.Unknown", "Prims.unit", "LowParse.Spec.Sum.synth_dsum_case_injective" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x))
[]
LowParse.Spec.Sum.parse_dsum_cases'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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 -> LowParse.Spec.Base.parser (LowParse.Spec.Sum.parse_dsum_cases_kind s f g x) (LowParse.Spec.Sum.dsum_cases s x)
{ "end_col": 124, "end_line": 657, "start_col": 2, "start_line": 654 }
Prims.Tot
val serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x)) = match x with | Known x' -> serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x) | Unknown x' -> serialize_ext g sg (parse_dsum_type_of_tag s f g x)
val serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x)) let serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x)) =
false
null
false
match x with | Known x' -> serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x) | Unknown x' -> serialize_ext g sg (parse_dsum_type_of_tag s f g x)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "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.Base.serializer", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Spec.Sum.dsum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Base.serialize_ext", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Sum.dsum_type_of_tag", "LowParse.Spec.Sum.parse_dsum_type_of_tag", "LowParse.Spec.Enum.unknown_enum_repr" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end )) = parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; begin match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k end let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x)) = let f (y: refine_with_tag (dsum_tag_of_data s) (x)) : Lemma (synth_dsum_case s x (synth_dsum_case_recip s x y) == y) = DSum?.synth_case_synth_case_recip s y in Classical.forall_intro f let serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x))
[]
LowParse.Spec.Sum.serialize_dsum_type_of_tag
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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))) -> sr: (x: LowParse.Spec.Sum.dsum_known_key s -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) -> g: LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_unknown_tag s) -> sg: LowParse.Spec.Base.serializer g -> x: LowParse.Spec.Sum.dsum_key s -> LowParse.Spec.Base.serializer (LowParse.Spec.Sum.parse_dsum_type_of_tag s f g x)
{ "end_col": 55, "end_line": 866, "start_col": 2, "start_line": 862 }
Prims.Tot
val parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)
val parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) =
false
null
false
match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "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.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Base.coerce", "LowParse.Spec.Sum.parse_dsum_cases_kind", "LowParse.Spec.Sum.dsum_type_of_tag", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.unknown_enum_repr" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x))
[]
LowParse.Spec.Sum.parse_dsum_type_of_tag'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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 -> LowParse.Spec.Base.parser (LowParse.Spec.Sum.parse_dsum_cases_kind s f g x) (LowParse.Spec.Sum.dsum_type_of_tag s x)
{ "end_col": 86, "end_line": 645, "start_col": 2, "start_line": 643 }
Prims.Pure
val serialize_dsum' (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: (x: dsum_key t -> Tot (parser k (dsum_cases t x)))) (sc: (x: dsum_key t -> Tot (serializer (pc x)))) : Pure (serializer (parse_dsum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_dsum' (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) (sc: ((x: dsum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_dsum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(kt) #(dsum_key t) #(parse_maybe_enum_key p (dsum_enum t)) (serialize_maybe_enum_key p s (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k #pc sc
val serialize_dsum' (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: (x: dsum_key t -> Tot (parser k (dsum_cases t x)))) (sc: (x: dsum_key t -> Tot (serializer (pc x)))) : Pure (serializer (parse_dsum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) let serialize_dsum' (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: (x: dsum_key t -> Tot (parser k (dsum_cases t x)))) (sc: (x: dsum_key t -> Tot (serializer (pc x)))) : Pure (serializer (parse_dsum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) =
false
null
false
serialize_tagged_union #(kt) #(dsum_key t) #(parse_maybe_enum_key p (dsum_enum t)) (serialize_maybe_enum_key p s (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k #pc sc
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Base.serializer", "LowParse.Spec.Sum.dsum_key", "LowParse.Spec.Sum.dsum_cases", "LowParse.Spec.Combinators.serialize_tagged_union", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Enum.serialize_maybe_enum_key", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_tag_of_data", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.Sum.parse_dsum'", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.l_True" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end )) = parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; begin match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k end let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x)) = let f (y: refine_with_tag (dsum_tag_of_data s) (x)) : Lemma (synth_dsum_case s x (synth_dsum_case_recip s x y) == y) = DSum?.synth_case_synth_case_recip s y in Classical.forall_intro f let serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x)) = match x with | Known x' -> serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x) | Unknown x' -> serialize_ext g sg (parse_dsum_type_of_tag s f g x) let serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_cases s f g x)) = synth_dsum_case_injective s x; synth_dsum_case_inverse s x; serialize_synth _ (synth_dsum_case s x) (serialize_dsum_type_of_tag s f sr g sg x) (synth_dsum_case_recip s x) () let serialize_dsum' (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) (sc: ((x: dsum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_dsum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_dsum' (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: (x: dsum_key t -> Tot (parser k (dsum_cases t x)))) (sc: (x: dsum_key t -> Tot (serializer (pc x)))) : Pure (serializer (parse_dsum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True))
[]
LowParse.Spec.Sum.serialize_dsum'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> s: LowParse.Spec.Base.serializer p -> sc: (x: LowParse.Spec.Sum.dsum_key t -> LowParse.Spec.Base.serializer (pc x)) -> Prims.Pure (LowParse.Spec.Base.serializer (LowParse.Spec.Sum.parse_dsum' t p pc))
{ "end_col": 6, "end_line": 906, "start_col": 2, "start_line": 897 }
FStar.Pervasives.Lemma
val parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k
val parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x))) let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x))) =
false
null
true
parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "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.parse", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Combinators.parse_synth_eq", "Prims.__proj__Mkdtuple2__item___1", "LowParse.Spec.Sum.sum_cases", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.synth_sum_case", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_injective", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "LowParse.Spec.Sum.parse_sum_eq'", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.parse_sum", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)))
[]
LowParse.Spec.Sum.parse_sum_eq
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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 -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_sum t p pc) input == (match LowParse.Spec.Base.parse (LowParse.Spec.Enum.parse_enum_key p (LowParse.Spec.Sum.sum_enum t)) input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ k consumed_k) -> let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in (match LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (pc k)) input_k with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> FStar.Pervasives.Native.Some (LowParse.Spec.Sum.synth_sum_case t k x, consumed_k + consumed_x)) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.sum_type t * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 61, "end_line": 231, "start_col": 2, "start_line": 225 }
FStar.Pervasives.Lemma
val parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input)
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input
val parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) =
false
null
true
synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "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.Bytes.bytes", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Combinators.parse_synth_eq", "Prims.__proj__Mkdtuple2__item___1", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_tag_of_data", "LowParse.Spec.Enum.Known", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.synth_dsum_case", "Prims.unit", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Base.weaken", "LowParse.Spec.Enum.unknown_enum_repr", "LowParse.Spec.Enum.Unknown", "LowParse.Spec.Sum.synth_dsum_case_injective", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Sum.dsum_cases", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_dsum_cases", "LowParse.Spec.Sum.parse_dsum_cases'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input)
[]
LowParse.Spec.Sum.parse_dsum_cases_eq'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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 -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum_cases s f g x) input == LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum_cases' s f g x) input)
{ "end_col": 59, "end_line": 675, "start_col": 2, "start_line": 668 }
Prims.Tot
val weaken_parse_cases_kind (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) : Tot parser_kind
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s))
val weaken_parse_cases_kind (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) : Tot parser_kind let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) : Tot parser_kind =
false
null
false
let keys:list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k , _ |) = f x in k else default_parser_kind) (List.Tot.map fst (sum_enum s))
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "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.glb_list_of", "LowParse.Spec.Sum.sum_key_type", "FStar.List.Tot.Base.mem", "Prims.bool", "LowParse.Spec.Base.default_parser_kind", "FStar.List.Tot.Base.map", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Sum.sum_repr_type", "FStar.Pervasives.Native.fst", "LowParse.Spec.Sum.sum_enum", "Prims.list" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val weaken_parse_cases_kind (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) : Tot parser_kind
[]
LowParse.Spec.Sum.weaken_parse_cases_kind
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.sum -> f: (x: LowParse.Spec.Sum.sum_key s -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag s x))) -> LowParse.Spec.Base.parser_kind
{ "end_col": 35, "end_line": 92, "start_col": 1, "start_line": 87 }
Prims.Tot
val parse_sum_cases (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x)
val parse_sum_cases (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) let parse_sum_cases (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) =
false
null
false
synth_sum_case_injective s x; (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) `parse_synth` (synth_sum_case s x)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "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.Combinators.parse_synth", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Base.weaken", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.synth_sum_case", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_injective" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_sum_cases (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x))
[]
LowParse.Spec.Sum.parse_sum_cases
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.sum -> f: (x: LowParse.Spec.Sum.sum_key s -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag s x))) -> x: LowParse.Spec.Sum.sum_key s -> LowParse.Spec.Base.parser (LowParse.Spec.Sum.weaken_parse_cases_kind s f) (LowParse.Spec.Sum.sum_cases s x)
{ "end_col": 86, "end_line": 109, "start_col": 2, "start_line": 108 }
FStar.Pervasives.Lemma
val parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input
val parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x))) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x))) =
false
null
true
parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Bytes.bytes", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Enum.maybe_enum_key_of_repr", "Prims.unit", "LowParse.Spec.Combinators.parse_tagged_union_eq", "LowParse.Spec.Sum.dsum_key", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_tag_of_data", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Sum.parse_dsum_cases", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_dsum", "FStar.Pervasives.Native.None", "LowParse.Spec.Sum.dsum_cases", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)))
[]
LowParse.Spec.Sum.parse_dsum_eq''
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) -> f: (x: LowParse.Spec.Sum.dsum_known_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) -> g: LowParse.Spec.Base.parser k' (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum t p f g) input == (match LowParse.Spec.Base.parse p input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ k' consumed_k) -> let k = LowParse.Spec.Enum.maybe_enum_key_of_repr (LowParse.Spec.Sum.dsum_enum t) k' in let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in (match LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum_cases t f g k) input_k with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> FStar.Pervasives.Native.Some (x, consumed_k + consumed_x)) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 63, "end_line": 732, "start_col": 2, "start_line": 731 }
FStar.Pervasives.Lemma
val serialize_dsum_eq (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_type s) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (serialize (serialize_dsum s st f sr g sg) x == (let tg = dsum_tag_of_data s x in (serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg) `Seq.append` (match tg with | Known k -> serialize (sr k) (synth_dsum_case_recip s tg x) | Unknown k -> serialize sg (synth_dsum_case_recip s tg x)))))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_dsum_eq (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_type s) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_dsum s st f sr g sg) x == ( let tg = dsum_tag_of_data s x in serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg `Seq.append` ( match tg with | Known k -> serialize (sr k) (synth_dsum_case_recip s tg x) | Unknown k -> serialize sg (synth_dsum_case_recip s tg x) )))) = serialize_dsum_eq' s st f sr g sg x; let tg = dsum_tag_of_data s x in synth_dsum_case_injective s tg; synth_dsum_case_inverse s tg; serialize_synth_eq _ (synth_dsum_case s tg) (serialize_dsum_type_of_tag s f sr g sg tg) (synth_dsum_case_recip s tg) () x
val serialize_dsum_eq (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_type s) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (serialize (serialize_dsum s st f sr g sg) x == (let tg = dsum_tag_of_data s x in (serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg) `Seq.append` (match tg with | Known k -> serialize (sr k) (synth_dsum_case_recip s tg x) | Unknown k -> serialize sg (synth_dsum_case_recip s tg x))))) let serialize_dsum_eq (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_type s) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (serialize (serialize_dsum s st f sr g sg) x == (let tg = dsum_tag_of_data s x in (serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg) `Seq.append` (match tg with | Known k -> serialize (sr k) (synth_dsum_case_recip s tg x) | Unknown k -> serialize sg (synth_dsum_case_recip s tg x))))) =
false
null
true
serialize_dsum_eq' s st f sr g sg x; let tg = dsum_tag_of_data s x in synth_dsum_case_injective s tg; synth_dsum_case_inverse s tg; serialize_synth_eq _ (synth_dsum_case s tg) (serialize_dsum_type_of_tag s f sr g sg tg) (synth_dsum_case_recip s tg) () x
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Base.serializer", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Combinators.serialize_synth_eq", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Sum.dsum_type_of_tag", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.Sum.dsum_key", "LowParse.Spec.Sum.dsum_tag_of_data", "LowParse.Spec.Sum.parse_dsum_type_of_tag", "LowParse.Spec.Sum.synth_dsum_case", "LowParse.Spec.Sum.serialize_dsum_type_of_tag", "LowParse.Spec.Sum.synth_dsum_case_recip", "Prims.unit", "LowParse.Spec.Sum.synth_dsum_case_inverse", "LowParse.Spec.Sum.synth_dsum_case_injective", "LowParse.Spec.Sum.serialize_dsum_eq'", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.squash", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "LowParse.Spec.Base.serialize", "LowParse.Spec.Sum.parse_dsum_kind", "LowParse.Spec.Sum.parse_dsum", "LowParse.Spec.Sum.serialize_dsum", "FStar.Seq.Base.append", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Spec.Enum.serialize_maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.unknown_enum_repr", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end )) = parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; begin match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k end let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x)) = let f (y: refine_with_tag (dsum_tag_of_data s) (x)) : Lemma (synth_dsum_case s x (synth_dsum_case_recip s x y) == y) = DSum?.synth_case_synth_case_recip s y in Classical.forall_intro f let serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x)) = match x with | Known x' -> serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x) | Unknown x' -> serialize_ext g sg (parse_dsum_type_of_tag s f g x) let serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_cases s f g x)) = synth_dsum_case_injective s x; synth_dsum_case_inverse s x; serialize_synth _ (synth_dsum_case s x) (serialize_dsum_type_of_tag s f sr g sg x) (synth_dsum_case_recip s x) () let serialize_dsum' (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) (sc: ((x: dsum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_dsum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(kt) #(dsum_key t) #(parse_maybe_enum_key p (dsum_enum t)) (serialize_maybe_enum_key p s (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k #pc sc let serialize_dsum (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) : Pure (serializer (parse_dsum s pt f g)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_dsum' s st #_ #(parse_dsum_cases s f g) (serialize_dsum_cases s f sr g sg) let synth_dsum_case_recip_synth_case_known_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_known_tag x) . {:pattern (synth_case_recip (Known x) (synth_case (Known x) y))} synth_case_recip (Known x) (synth_case (Known x) y) == y ) let synth_dsum_case_recip_synth_case_unknown_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: repr) : GTot Type0 = list_mem x (list_map snd e) == false ==> ( forall (y: type_of_unknown_tag) . {:pattern (synth_case_recip (Unknown x) (synth_case (Unknown x) y))} synth_case_recip (Unknown x) (synth_case (Unknown x) y) == y ) inline_for_extraction let make_dsum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) : Tot ( (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum ) = DSum key repr e data tag_of_data inline_for_extraction let make_dsum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (synth_case_recip_synth_case_known: ( (x: key) -> Tot (squash (synth_dsum_case_recip_synth_case_known_post e tag_of_data type_of_known_tag type_of_unknown_tag synth_case synth_case_recip x)) )) (synth_case_recip_synth_case_unknown: ( (x: repr) -> Tot (squash (synth_dsum_case_recip_synth_case_unknown_post e tag_of_data type_of_known_tag type_of_unknown_tag synth_case synth_case_recip x)) )) : Tot ( (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum ) = make_dsum e tag_of_data type_of_known_tag type_of_unknown_tag synth_case synth_case_recip (fun x y -> match x with | Known x' -> synth_case_recip_synth_case_known x' | Unknown x' -> synth_case_recip_synth_case_unknown x' ) let serialize_dsum_eq' (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_type s) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_dsum s st f sr g sg) x == ( let tg = dsum_tag_of_data s x in serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg `Seq.append` serialize (serialize_dsum_cases s f sr g sg tg) x ))) = () let serialize_dsum_eq (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_type s) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_dsum s st f sr g sg) x == ( let tg = dsum_tag_of_data s x in serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg `Seq.append` ( match tg with | Known k -> serialize (sr k) (synth_dsum_case_recip s tg x) | Unknown k -> serialize sg (synth_dsum_case_recip s tg x)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_dsum_eq (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_type s) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (serialize (serialize_dsum s st f sr g sg) x == (let tg = dsum_tag_of_data s x in (serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg) `Seq.append` (match tg with | Known k -> serialize (sr k) (synth_dsum_case_recip s tg x) | Unknown k -> serialize sg (synth_dsum_case_recip s tg x)))))
[]
LowParse.Spec.Sum.serialize_dsum_eq
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.dsum -> st: LowParse.Spec.Base.serializer pt -> 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))) -> sr: (x: LowParse.Spec.Sum.dsum_known_key s -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) -> g: LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_unknown_tag s) -> sg: LowParse.Spec.Base.serializer g -> x: LowParse.Spec.Sum.dsum_type s -> FStar.Pervasives.Lemma (requires Mkparser_kind'?.parser_kind_subkind kt == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong) (ensures LowParse.Spec.Base.serialize (LowParse.Spec.Sum.serialize_dsum s st f sr g sg) x == (let tg = LowParse.Spec.Sum.dsum_tag_of_data s x in FStar.Seq.Base.append (LowParse.Spec.Base.serialize (LowParse.Spec.Enum.serialize_maybe_enum_key pt st (LowParse.Spec.Sum.dsum_enum s)) tg) (match tg with | LowParse.Spec.Enum.Known #_ #_ #_ k -> LowParse.Spec.Base.serialize (sr k) (LowParse.Spec.Sum.synth_dsum_case_recip s tg x) | LowParse.Spec.Enum.Unknown #_ #_ #_ _ -> LowParse.Spec.Base.serialize sg (LowParse.Spec.Sum.synth_dsum_case_recip s tg x))))
{ "end_col": 5, "end_line": 1073, "start_col": 2, "start_line": 1063 }
FStar.Pervasives.Lemma
val synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k)
val synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) =
false
null
true
Classical.forall_intro (Sum?.synth_case_recip_synth_case s k)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "FStar.Classical.forall_intro", "LowParse.Spec.Sum.__proj__Sum__item__type_of_tag", "Prims.eq2", "LowParse.Spec.Sum.__proj__Sum__item__tag_of_data", "LowParse.Spec.Sum.__proj__Sum__item__synth_case", "LowParse.Spec.Sum.synth_case_recip'", "LowParse.Spec.Sum.__proj__Sum__item__key", "LowParse.Spec.Sum.__proj__Sum__item__repr", "LowParse.Spec.Sum.__proj__Sum__item__e", "LowParse.Spec.Sum.__proj__Sum__item__data", "LowParse.Spec.Sum.__proj__Sum__item__synth_case_recip", "LowParse.Spec.Sum.__proj__Sum__item__synth_case_recip_synth_case", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_injective", "LowParse.Spec.Sum.sum_type_of_tag", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Sum.synth_sum_case", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k))
[]
LowParse.Spec.Sum.synth_sum_case_injective
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.sum -> k: LowParse.Spec.Sum.sum_key s -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_injective (LowParse.Spec.Sum.synth_sum_case s k))
{ "end_col": 63, "end_line": 101, "start_col": 2, "start_line": 101 }
FStar.Pervasives.Lemma
val parse_sum_cases_eq' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input)
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input
val parse_sum_cases_eq' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) =
false
null
true
synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "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.Bytes.bytes", "LowParse.Spec.Combinators.parse_synth_eq", "Prims.__proj__Mkdtuple2__item___1", "LowParse.Spec.Sum.sum_cases", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.synth_sum_case", "Prims.unit", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Base.weaken", "LowParse.Spec.Sum.synth_sum_case_injective", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_sum_cases", "LowParse.Spec.Sum.parse_sum_cases'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_sum_cases_eq' (s: sum) (f: (x: sum_key s -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input)
[]
LowParse.Spec.Sum.parse_sum_cases_eq'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.sum -> f: (x: LowParse.Spec.Sum.sum_key s -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.sum_type_of_tag s x))) -> x: LowParse.Spec.Sum.sum_key s -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_sum_cases s f x) input == LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_sum_cases' s f x) input)
{ "end_col": 56, "end_line": 142, "start_col": 2, "start_line": 140 }
Prims.Pure
val sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k
val sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) =
false
null
false
k
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[]
[ "LowParse.Spec.Sum.sum", "LowParse.Spec.Sum.sum_key", "LowParse.Spec.Sum.sum_key_type", "Prims.l_True", "Prims.eq2" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t)))
[]
LowParse.Spec.Sum.sum_key_type_of_sum_key
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.sum -> k: LowParse.Spec.Sum.sum_key t -> Prims.Pure (LowParse.Spec.Sum.sum_key_type t)
{ "end_col": 3, "end_line": 62, "start_col": 2, "start_line": 62 }
Prims.GTot
val synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: (x: enum_key e -> y: type_of_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: enum_key e -> x: refine_with_tag tag_of_data k -> Tot (type_of_tag k))) (x: key) : GTot Type0
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y )
val synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: (x: enum_key e -> y: type_of_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: enum_key e -> x: refine_with_tag tag_of_data k -> Tot (type_of_tag k))) (x: key) : GTot Type0 let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: (x: enum_key e -> y: type_of_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: enum_key e -> x: refine_with_tag tag_of_data k -> Tot (type_of_tag k))) (x: key) : GTot Type0 =
false
null
false
list_mem x (list_map fst e) ==> (forall (y: type_of_tag x). {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "sometrivial" ]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Base.refine_with_tag", "Prims.l_imp", "Prims.b2t", "LowParse.Spec.Enum.list_mem", "LowParse.Spec.Enum.list_map", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.fst", "Prims.l_Forall", "Prims.eq2", "LowParse.Spec.Sum.synth_case_recip'" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: (x: enum_key e -> y: type_of_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: enum_key e -> x: refine_with_tag tag_of_data k -> Tot (type_of_tag k))) (x: key) : GTot Type0
[]
LowParse.Spec.Sum.synth_case_recip_synth_case_post
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: LowParse.Spec.Enum.enum key repr -> tag_of_data: (_: data -> LowParse.Spec.Enum.enum_key e) -> type_of_tag: (_: LowParse.Spec.Enum.enum_key e -> Type) -> synth_case: (x: LowParse.Spec.Enum.enum_key e -> y: type_of_tag x -> LowParse.Spec.Base.refine_with_tag tag_of_data x) -> synth_case_recip: (k: LowParse.Spec.Enum.enum_key e -> x: LowParse.Spec.Base.refine_with_tag tag_of_data k -> type_of_tag k) -> x: key -> Prims.GTot Type0
{ "end_col": 3, "end_line": 388, "start_col": 2, "start_line": 385 }
Prims.Pure
val serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc)
val serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) =
false
null
false
serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Base.serializer", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.serialize_sum'", "LowParse.Spec.Sum.weaken_parse_cases_kind", "LowParse.Spec.Sum.parse_sum_cases", "LowParse.Spec.Sum.serialize_sum_cases", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Sum.parse_sum", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.l_True" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True))
[]
LowParse.Spec.Sum.serialize_sum
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.sum -> s: LowParse.Spec.Base.serializer p -> sc: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (pc x))) -> Prims.Pure (LowParse.Spec.Base.serializer (LowParse.Spec.Sum.parse_sum t p pc))
{ "end_col": 77, "end_line": 327, "start_col": 2, "start_line": 327 }
Prims.Tot
val weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (k': parser_kind) : Tot parser_kind
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k'
val weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (k': parser_kind) : Tot parser_kind let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (k': parser_kind) : Tot parser_kind =
false
null
false
let keys:list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in (glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k , _ |) = f x in k else k') (List.Tot.map fst (dsum_enum s))) `glb` k'
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "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.Base.glb", "LowParse.Spec.Base.glb_list_of", "LowParse.Spec.Sum.dsum_key_type", "FStar.List.Tot.Base.mem", "Prims.bool", "FStar.List.Tot.Base.map", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Sum.dsum_repr_type", "FStar.Pervasives.Native.fst", "LowParse.Spec.Sum.dsum_enum", "Prims.list" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (k': parser_kind) : Tot parser_kind
[]
LowParse.Spec.Sum.weaken_parse_dsum_cases_kind
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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))) -> k': LowParse.Spec.Base.parser_kind -> LowParse.Spec.Base.parser_kind
{ "end_col": 45, "end_line": 552, "start_col": 1, "start_line": 547 }
Prims.Tot
val parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)
val parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) =
false
null
false
match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "total" ]
[ "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.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Base.coerce", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Sum.dsum_type_of_tag", "LowParse.Spec.Base.weaken", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Enum.unknown_enum_repr" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x))
[]
LowParse.Spec.Sum.parse_dsum_type_of_tag
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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 -> LowParse.Spec.Base.parser (LowParse.Spec.Sum.weaken_parse_dsum_cases_kind s f k) (LowParse.Spec.Sum.dsum_type_of_tag s x)
{ "end_col": 135, "end_line": 613, "start_col": 2, "start_line": 611 }
FStar.Pervasives.Lemma
val synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g
val synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) =
false
null
true
let f (y1 y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1:squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2:squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1 y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Sum.dsum", "LowParse.Spec.Sum.dsum_key", "FStar.Classical.forall_intro_2", "LowParse.Spec.Sum.dsum_type_of_tag", "Prims.l_imp", "Prims.eq2", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_tag_of_data", "LowParse.Spec.Sum.synth_dsum_case", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Classical.move_requires", "Prims._assert", "LowParse.Spec.Sum.synth_dsum_case_recip", "LowParse.Spec.Sum.__proj__DSum__item__synth_case_recip_synth_case", "LowParse.Spec.Combinators.synth_injective" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x))
[]
LowParse.Spec.Sum.synth_dsum_case_injective
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.dsum -> x: LowParse.Spec.Sum.dsum_key s -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_injective (LowParse.Spec.Sum.synth_dsum_case s x))
{ "end_col": 28, "end_line": 602, "start_col": 1, "start_line": 579 }
FStar.Pervasives.Lemma
val serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (serialize (serialize_sum t s sc) x == (let tg = sum_tag_of_data t x in (serialize (serialize_enum_key _ s (sum_enum t)) tg) `Seq.append` (serialize (sc tg) (synth_sum_case_recip t tg x)))))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x
val serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (serialize (serialize_sum t s sc) x == (let tg = sum_tag_of_data t x in (serialize (serialize_enum_key _ s (sum_enum t)) tg) `Seq.append` (serialize (sc tg) (synth_sum_case_recip t tg x))))) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (serialize (serialize_sum t s sc) x == (let tg = sum_tag_of_data t x in (serialize (serialize_enum_key _ s (sum_enum t)) tg) `Seq.append` (serialize (sc tg) (synth_sum_case_recip t tg x))))) =
false
null
true
let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.sum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.sum_repr_type", "LowParse.Spec.Base.serializer", "LowParse.Spec.Sum.sum_key", "Prims.dtuple2", "LowParse.Spec.Sum.sum_type_of_tag", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Combinators.serialize_synth_eq", "LowParse.Spec.Sum.sum_cases", "LowParse.Spec.Sum.synth_sum_case", "LowParse.Spec.Sum.synth_sum_case_recip", "Prims.unit", "LowParse.Spec.Sum.synth_sum_case_inverse", "LowParse.Spec.Sum.synth_sum_case_injective", "LowParse.Spec.Sum.sum_tag_of_data", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.squash", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "LowParse.Spec.Base.serialize", "LowParse.Spec.Sum.parse_sum_kind", "LowParse.Spec.Sum.parse_sum", "LowParse.Spec.Sum.serialize_sum", "FStar.Seq.Base.append", "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.Enum.serialize_enum_key", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x)
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (serialize (serialize_sum t s sc) x == (let tg = sum_tag_of_data t x in (serialize (serialize_enum_key _ s (sum_enum t)) tg) `Seq.append` (serialize (sc tg) (synth_sum_case_recip t tg x)))))
[]
LowParse.Spec.Sum.serialize_sum_eq
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.sum -> s: LowParse.Spec.Base.serializer p -> sc: (x: LowParse.Spec.Sum.sum_key t -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (pc x))) -> x: LowParse.Spec.Sum.sum_type t -> FStar.Pervasives.Lemma (requires Mkparser_kind'?.parser_kind_subkind kt == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong) (ensures LowParse.Spec.Base.serialize (LowParse.Spec.Sum.serialize_sum t s sc) x == (let tg = LowParse.Spec.Sum.sum_tag_of_data t x in FStar.Seq.Base.append (LowParse.Spec.Base.serialize (LowParse.Spec.Enum.serialize_enum_key p s (LowParse.Spec.Sum.sum_enum t)) tg) (LowParse.Spec.Base.serialize (sc tg) (LowParse.Spec.Sum.synth_sum_case_recip t tg x))))
{ "end_col": 99, "end_line": 348, "start_col": 1, "start_line": 345 }
FStar.Pervasives.Lemma
val parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> (match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)) | _ -> None))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input
val parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> (match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)) | _ -> None)) let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> (match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)) | _ -> None)) =
false
null
true
parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "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.Enum.parse_enum_key_eq", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "Prims.unit", "LowParse.Spec.Sum.parse_sum_eq", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Sum.sum_type", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_sum", "FStar.Pervasives.Native.None", "LowParse.Spec.Enum.enum_key", "FStar.Pervasives.dsnd", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "LowParse.Spec.Sum.synth_sum_case", "Prims.op_Addition", "LowParse.Spec.Enum.maybe_enum_key", "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" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> (match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)) | _ -> None))
[]
LowParse.Spec.Sum.parse_sum_eq''
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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 -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_sum t p pc) input == (match LowParse.Spec.Base.parse p input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ 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 -> (match LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (pc k)) input_k with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> FStar.Pervasives.Native.Some (LowParse.Spec.Sum.synth_sum_case t k x, consumed_k + consumed_x)) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.sum_type t * LowParse.Spec.Base.consumed_length input) | _ -> FStar.Pervasives.Native.None) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.sum_type t * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 40, "end_line": 255, "start_col": 2, "start_line": 254 }
FStar.Pervasives.Lemma
val parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input
val parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x))) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x))) =
false
null
true
parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "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.Combinators.parse_tagged_union_eq_gen", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Sum.sum_key_type", "LowParse.Spec.Sum.sum_enum", "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", "Prims.unit", "FStar.Pervasives.dfst", "LowParse.Spec.Sum.parse_sum_cases'", "LowParse.Spec.Sum.parse_sum_cases_eq'", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_sum", "LowParse.Spec.Enum.enum_key", "FStar.Pervasives.Native.None", "LowParse.Spec.Sum.sum_cases", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x)))
[]
LowParse.Spec.Sum.parse_sum_eq'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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 -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_sum t p pc) input == (match LowParse.Spec.Base.parse (LowParse.Spec.Enum.parse_enum_key p (LowParse.Spec.Sum.sum_enum t)) input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ k consumed_k) -> let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in (match LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_sum_cases' t pc k) input_k with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> FStar.Pervasives.Native.Some (x, consumed_k + consumed_x)) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.sum_type t * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 9, "end_line": 207, "start_col": 2, "start_line": 195 }
FStar.Pervasives.Lemma
val parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input
val parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x))) let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x))) =
false
null
true
parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Bytes.bytes", "LowParse.Spec.Enum.parse_maybe_enum_key_eq", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_enum", "Prims.unit", "LowParse.Spec.Sum.parse_dsum_eq_", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_dsum", "FStar.Pervasives.Native.None", "LowParse.Spec.Sum.dsum_cases", "LowParse.Spec.Sum.parse_dsum_cases'", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.maybe_enum_key_of_repr", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)))
[]
LowParse.Spec.Sum.parse_dsum_eq'
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) -> f: (x: LowParse.Spec.Sum.dsum_known_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) -> g: LowParse.Spec.Base.parser k' (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum t p f g) input == (match LowParse.Spec.Base.parse p input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ k' consumed_k) -> let k = LowParse.Spec.Enum.maybe_enum_key_of_repr (LowParse.Spec.Sum.dsum_enum t) k' in let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in (match LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum_cases' t f g k) input_k with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> FStar.Pervasives.Native.Some (x, consumed_k + consumed_x)) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 47, "end_line": 774, "start_col": 2, "start_line": 773 }
FStar.Pervasives.Lemma
val parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input
val parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x))) let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x))) =
false
null
true
parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Bytes.bytes", "LowParse.Spec.Combinators.parse_tagged_union_eq_gen", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_tag_of_data", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Sum.parse_dsum_cases", "Prims.unit", "LowParse.Spec.Sum.parse_dsum_cases_kind", "LowParse.Spec.Sum.parse_dsum_cases'", "LowParse.Spec.Sum.parse_dsum_cases_eq'", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_dsum", "FStar.Pervasives.Native.None", "LowParse.Spec.Sum.dsum_cases", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)))
[]
LowParse.Spec.Sum.parse_dsum_eq_
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) -> f: (x: LowParse.Spec.Sum.dsum_known_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) -> g: LowParse.Spec.Base.parser k' (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum t p f g) input == (match LowParse.Spec.Base.parse (LowParse.Spec.Enum.parse_maybe_enum_key p (LowParse.Spec.Sum.dsum_enum t)) input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ k consumed_k) -> let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in (match LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum_cases' t f g k) input_k with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> FStar.Pervasives.Native.Some (x, consumed_k + consumed_x)) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 285, "end_line": 752, "start_col": 2, "start_line": 752 }
Prims.GTot
val synth_dsum_case_recip_synth_case_unknown_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: (x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: repr) : GTot Type0
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_dsum_case_recip_synth_case_unknown_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: repr) : GTot Type0 = list_mem x (list_map snd e) == false ==> ( forall (y: type_of_unknown_tag) . {:pattern (synth_case_recip (Unknown x) (synth_case (Unknown x) y))} synth_case_recip (Unknown x) (synth_case (Unknown x) y) == y )
val synth_dsum_case_recip_synth_case_unknown_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: (x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: repr) : GTot Type0 let synth_dsum_case_recip_synth_case_unknown_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: (x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: repr) : GTot Type0 =
false
null
false
list_mem x (list_map snd e) == false ==> (forall (y: type_of_unknown_tag). {:pattern (synth_case_recip (Unknown x) (synth_case (Unknown x) y))} synth_case_recip (Unknown x) (synth_case (Unknown x) y) == y)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "sometrivial" ]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Sum.dsum_type_of_tag'", "LowParse.Spec.Base.refine_with_tag", "Prims.l_imp", "Prims.eq2", "Prims.bool", "LowParse.Spec.Enum.list_mem", "LowParse.Spec.Enum.list_map", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.snd", "Prims.l_Forall", "LowParse.Spec.Enum.Unknown" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end )) = parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; begin match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k end let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x)) = let f (y: refine_with_tag (dsum_tag_of_data s) (x)) : Lemma (synth_dsum_case s x (synth_dsum_case_recip s x y) == y) = DSum?.synth_case_synth_case_recip s y in Classical.forall_intro f let serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x)) = match x with | Known x' -> serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x) | Unknown x' -> serialize_ext g sg (parse_dsum_type_of_tag s f g x) let serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_cases s f g x)) = synth_dsum_case_injective s x; synth_dsum_case_inverse s x; serialize_synth _ (synth_dsum_case s x) (serialize_dsum_type_of_tag s f sr g sg x) (synth_dsum_case_recip s x) () let serialize_dsum' (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) (sc: ((x: dsum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_dsum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(kt) #(dsum_key t) #(parse_maybe_enum_key p (dsum_enum t)) (serialize_maybe_enum_key p s (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k #pc sc let serialize_dsum (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) : Pure (serializer (parse_dsum s pt f g)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_dsum' s st #_ #(parse_dsum_cases s f g) (serialize_dsum_cases s f sr g sg) let synth_dsum_case_recip_synth_case_known_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_known_tag x) . {:pattern (synth_case_recip (Known x) (synth_case (Known x) y))} synth_case_recip (Known x) (synth_case (Known x) y) == y ) let synth_dsum_case_recip_synth_case_unknown_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: repr) : GTot Type0
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_dsum_case_recip_synth_case_unknown_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case: (x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: (k: maybe_enum_key e -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (x: repr) : GTot Type0
[]
LowParse.Spec.Sum.synth_dsum_case_recip_synth_case_unknown_post
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: LowParse.Spec.Enum.enum key repr -> tag_of_data: (_: data -> LowParse.Spec.Enum.maybe_enum_key e) -> type_of_known_tag: (_: LowParse.Spec.Enum.enum_key e -> Type) -> type_of_unknown_tag: Type -> synth_case: ( x: LowParse.Spec.Enum.maybe_enum_key e -> y: LowParse.Spec.Sum.dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x -> LowParse.Spec.Base.refine_with_tag tag_of_data x) -> synth_case_recip: (k: LowParse.Spec.Enum.maybe_enum_key e -> _: LowParse.Spec.Base.refine_with_tag tag_of_data k -> LowParse.Spec.Sum.dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k) -> x: repr -> Prims.GTot Type0
{ "end_col": 3, "end_line": 955, "start_col": 2, "start_line": 952 }
Prims.Pure
val serialize_dsum (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) : Pure (serializer (parse_dsum s pt f g)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_dsum (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) : Pure (serializer (parse_dsum s pt f g)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_dsum' s st #_ #(parse_dsum_cases s f g) (serialize_dsum_cases s f sr g sg)
val serialize_dsum (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) : Pure (serializer (parse_dsum s pt f g)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) let serialize_dsum (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) : Pure (serializer (parse_dsum s pt f g)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) =
false
null
false
serialize_dsum' s st #_ #(parse_dsum_cases s f g) (serialize_dsum_cases s f sr g sg)
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Base.serializer", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Spec.Sum.serialize_dsum'", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Sum.parse_dsum_cases", "LowParse.Spec.Sum.serialize_dsum_cases", "LowParse.Spec.Sum.parse_dsum_kind", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.parse_dsum", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.l_True" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end )) = parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; begin match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k end let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let synth_dsum_case_inverse (s: dsum) (x: dsum_key s) : Lemma (synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x)) = let f (y: refine_with_tag (dsum_tag_of_data s) (x)) : Lemma (synth_dsum_case s x (synth_dsum_case_recip s x y) == y) = DSum?.synth_case_synth_case_recip s y in Classical.forall_intro f let serialize_dsum_type_of_tag (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_type_of_tag s f g x)) = match x with | Known x' -> serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x) | Unknown x' -> serialize_ext g sg (parse_dsum_type_of_tag s f g x) let serialize_dsum_cases (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) (x: dsum_key s) : Tot (serializer (parse_dsum_cases s f g x)) = synth_dsum_case_injective s x; synth_dsum_case_inverse s x; serialize_synth _ (synth_dsum_case s x) (serialize_dsum_type_of_tag s f sr g sg x) (synth_dsum_case_recip s x) () let serialize_dsum' (#kt: parser_kind) (t: dsum) (#p: parser kt (dsum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) (sc: ((x: dsum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_dsum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(kt) #(dsum_key t) #(parse_maybe_enum_key p (dsum_enum t)) (serialize_maybe_enum_key p s (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k #pc sc let serialize_dsum (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x)))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) : Pure (serializer (parse_dsum s pt f g)) (requires (kt.parser_kind_subkind == Some ParserStrong))
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_dsum (#kt: parser_kind) (s: dsum) (#pt: parser kt (dsum_repr_type s)) (st: serializer pt) (f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))) (sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x))))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag s)) (sg: serializer g) : Pure (serializer (parse_dsum s pt f g)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True))
[]
LowParse.Spec.Sum.serialize_dsum
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Sum.dsum -> st: LowParse.Spec.Base.serializer pt -> 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))) -> sr: (x: LowParse.Spec.Sum.dsum_known_key s -> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) -> g: LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_unknown_tag s) -> sg: LowParse.Spec.Base.serializer g -> Prims.Pure (LowParse.Spec.Base.serializer (LowParse.Spec.Sum.parse_dsum s pt f g))
{ "end_col": 86, "end_line": 921, "start_col": 2, "start_line": 921 }
FStar.Pervasives.Lemma
val parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match k with | Known k' -> (match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)) | Unknown k' -> match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end )) = parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; begin match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k end
val parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match k with | Known k' -> (match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)) | Unknown k' -> match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))) let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match k with | Known k' -> (match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)) | Unknown k' -> match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))) =
false
null
true
parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Bytes.bytes", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_enum", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Sum.weaken_parse_dsum_cases_kind", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.Sum.dsum_key", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Sum.dsum_tag_of_data", "LowParse.Spec.Base.weaken", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Sum.synth_dsum_case", "Prims.unit", "LowParse.Spec.Enum.unknown_enum_repr", "LowParse.Spec.Sum.synth_dsum_case_injective", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.parse", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Spec.Sum.parse_dsum_eq_", "Prims.l_True", "Prims.squash", "Prims.eq2", "LowParse.Spec.Sum.parse_dsum", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in match k with | Known k' -> (match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)) | Unknown k' -> match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)))
[]
LowParse.Spec.Sum.parse_dsum_eq
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) -> f: (x: LowParse.Spec.Sum.dsum_known_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) -> g: LowParse.Spec.Base.parser k' (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum t p f g) input == (match LowParse.Spec.Base.parse (LowParse.Spec.Enum.parse_maybe_enum_key p (LowParse.Spec.Sum.dsum_enum t)) input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ k consumed_k) -> let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in (match k with | LowParse.Spec.Enum.Known #_ #_ #_ k' -> (match LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (f k')) input_k with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> FStar.Pervasives.Native.Some (LowParse.Spec.Sum.synth_dsum_case t k x, consumed_k + consumed_x)) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t * LowParse.Spec.Base.consumed_length input) | LowParse.Spec.Enum.Unknown #_ #_ #_ _ -> (match LowParse.Spec.Base.parse g input_k with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> FStar.Pervasives.Native.Some (LowParse.Spec.Sum.synth_dsum_case t k x, consumed_k + consumed_x)) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t * LowParse.Spec.Base.consumed_length input)) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 7, "end_line": 816, "start_col": 2, "start_line": 802 }
FStar.Pervasives.Lemma
val parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input
val parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))) let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))) =
false
null
true
parse_dsum_eq t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input
{ "checked_file": "LowParse.Spec.Sum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Sum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Sum.dsum", "LowParse.Spec.Base.parser", "LowParse.Spec.Sum.dsum_repr_type", "LowParse.Spec.Sum.dsum_known_key", "Prims.dtuple2", "LowParse.Spec.Sum.dsum_type_of_known_tag", "LowParse.Spec.Sum.dsum_type_of_unknown_tag", "LowParse.Bytes.bytes", "LowParse.Spec.Enum.parse_maybe_enum_key_eq", "LowParse.Spec.Sum.dsum_key_type", "LowParse.Spec.Sum.dsum_enum", "Prims.unit", "LowParse.Spec.Sum.parse_dsum_eq", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Sum.dsum_type", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.Sum.parse_dsum", "FStar.Pervasives.Native.None", "LowParse.Spec.Sum.dsum_type_of_tag", "LowParse.Spec.Sum.parse_dsum_type_of_tag'", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "LowParse.Spec.Sum.synth_dsum_case", "Prims.op_Addition", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.maybe_enum_key_of_repr", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Sum include LowParse.Spec.Enum module Seq = FStar.Seq let synth_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: data) : GTot (type_of_tag (tag_of_data x)) = synth_case_recip (tag_of_data x) x noeq type sum = | Sum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (enum_key e))) -> (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> sum inline_for_extraction let sum_key_type (t: sum) : Tot eqtype = match t with (Sum key _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let sum_repr_type (t: sum) : Tot eqtype = match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr inline_for_extraction let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) = match t with (Sum _ _ e _ _ _ _ _ _ _) -> e inline_for_extraction let sum_key (t: sum) : Tot Type = enum_key (sum_enum t) inline_for_extraction let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t) (requires True) (ensures (fun k' -> k' == (k <: sum_key_type t))) = k inline_for_extraction let sum_type (t: sum) : Tot Type = match t with | Sum _ _ _ data _ _ _ _ _ _ -> data inline_for_extraction let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) = match t with | Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data inline_for_extraction let sum_cases (t: sum) (x: sum_key t) : Type = refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x inline_for_extraction let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type = match t with | Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag let weaken_parse_cases_kind (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) : Tot parser_kind = let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else default_parser_kind ) (List.Tot.map fst (sum_enum s)) inline_for_extraction let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) = match s with | Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma (synth_injective (synth_sum_case s k)) = Classical.forall_intro (Sum?.synth_case_recip_synth_case s k) let parse_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x)) = synth_sum_case_injective s x; weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x) let parse_sum_cases_eq (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with | None -> None | Some (y, consumed) -> Some (synth_sum_case s x y, consumed) )) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input let parse_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) : Tot (parser (dfst (f x)) (sum_cases s x)) = synth_sum_case_injective s x; dsnd (f x) `parse_synth` synth_sum_case s x let parse_sum_cases_eq' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (x: sum_key s) (input: bytes) : Lemma (parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input) = synth_sum_case_injective s x; parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input; parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input let parse_sum' (#kt: parser_kind) (t: sum) (p: parser kt (sum_repr_type t)) (#k: parser_kind) (pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) : Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t)) = parse_tagged_union #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k pc inline_for_extraction let parse_sum_kind (kt: parser_kind) (t: sum) (pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x)))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc) let parse_sum (#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)))) : Tot (parser (parse_sum_kind kt t pc) (sum_type t)) = parse_sum' t p (parse_sum_cases t pc) let parse_sum_eq' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match // parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k parse (parse_sum_cases' t pc k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen #(parse_filter_kind kt) #(sum_key t) (parse_enum_key p (sum_enum t)) #(sum_type t) (sum_tag_of_data t) (parse_sum_cases t pc) (parse_enum_key p (sum_enum t)) (fun input -> ()) (fun k -> dfst (pc k)) (parse_sum_cases' t pc) (fun k input -> parse_sum_cases_eq' t pc k input) input let parse_sum_eq (#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) : Lemma (parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end )) = parse_sum_eq' t p pc input; match parse (parse_enum_key p (sum_enum t)) input with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_sum_case_injective t k; parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k let parse_sum_eq'' (#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) : Lemma (parse (parse_sum t p pc) input == (match parse p input with | None -> None | 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 -> begin match parse (dsnd (pc k)) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x) end | _ -> None end )) = parse_sum_eq t p pc input; parse_enum_key_eq p (sum_enum t) input inline_for_extraction let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) = match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) -> synth_case_recip k x let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma (synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k)) = Classical.forall_intro (Sum?.synth_case_synth_case_recip s) let serialize_sum_cases' (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases' s f x)) = synth_sum_case_injective s x; synth_sum_case_inverse s x; (serialize_synth _ (synth_sum_case s x) (sr x) (synth_sum_case_recip s x) () ) let serialize_sum_cases (s: sum) (f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x))) (sr: (x: sum_key s) -> Tot (serializer (dsnd (f x)))) (x: sum_key s) : Tot (serializer (parse_sum_cases s f x)) = Classical.forall_intro (parse_sum_cases_eq' s f x); serialize_ext (parse_sum_cases' s f x) (serialize_sum_cases' s f sr x) (parse_sum_cases s f x) let serialize_sum' (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#k: parser_kind) (#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x)))) (sc: ((x: sum_key t) -> Tot (serializer (pc x)))) : Pure (serializer (parse_sum' t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = serialize_tagged_union #(parse_filter_kind kt) #(sum_key t) #(parse_enum_key p (sum_enum t)) (serialize_enum_key p s (sum_enum t)) #(sum_type t) (sum_tag_of_data t) #k #pc sc let serialize_sum (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) : Pure (serializer (parse_sum t p pc)) (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures (fun _ -> True)) = // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion) serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc) let serialize_sum_eq (#kt: parser_kind) (t: sum) (#p: parser kt (sum_repr_type t)) (s: serializer p) (#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))))) (x: sum_type t) : Lemma (requires (kt.parser_kind_subkind == Some ParserStrong)) (ensures ( serialize (serialize_sum t s sc) x == ( let tg = sum_tag_of_data t x in serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append` serialize (sc tg) (synth_sum_case_recip t tg x) ))) = let tg = sum_tag_of_data t x in synth_sum_case_injective t tg; synth_sum_case_inverse t tg; serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x inline_for_extraction let make_sum (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) : Tot ( (type_of_tag: (enum_key e -> Tot Type)) -> (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) -> (synth_case_recip_synth_case: ( (x: enum_key e) -> (y: type_of_tag x) -> Lemma (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y) )) -> (synth_case_synth_case_recip: ( (x: data) -> Lemma (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x) )) -> Tot sum) = Sum key repr e data tag_of_data let synth_case_recip_synth_case_post (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (x: key) : GTot Type0 = list_mem x (list_map fst e) ==> ( forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))} synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y ) inline_for_extraction let make_sum' (#key #repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> Tot (enum_key e))) (type_of_tag: (enum_key e -> Tot Type)) (synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) (synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) (synth_case_recip_synth_case: ( (x: key) -> Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x)) )) (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) )) : Tot sum = make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y -> let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) = synth_case_recip_synth_case x in assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)) (fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)) (* Sum with default case *) inline_for_extraction let dsum_type_of_tag' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (k: maybe_enum_key e) : Type = match k with | Unknown _ -> type_of_unknown_tag | Known k -> type_of_known_tag k let synth_dsum_case' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x)))) (synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x)))) (xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)) : GTot data = let (| x, y |) = xy in match x with | Unknown x -> synth_unknown_case x y | Known x -> synth_known_case x y let synth_dsum_case_recip' (#key: eqtype) (#repr: eqtype) (e: enum key repr) (#data: Type) (tag_of_data: (data -> GTot (maybe_enum_key e))) (type_of_known_tag: (enum_key e -> Tot Type)) (type_of_unknown_tag: Type) (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) (y: data) : GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) = let tg = tag_of_data y in (| tg, synth_case_recip tg y |) noeq type dsum = | DSum: (key: eqtype) -> (repr: eqtype) -> (e: enum key repr) -> (data: Type) -> (tag_of_data: (data -> Tot (maybe_enum_key e))) -> (type_of_known_tag: (enum_key e -> Tot Type)) -> (type_of_unknown_tag: Type) -> (synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) -> (synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) -> (synth_case_recip_synth_case: ( (x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (squash (synth_case_recip x (synth_case x y) == y) ) )) -> (synth_case_synth_case_recip: ( (x: data) -> Tot (squash (synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x) ) )) -> dsum inline_for_extraction let dsum_key_type (t: dsum) : Tot eqtype = match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key inline_for_extraction let dsum_repr_type (t: dsum) : Tot eqtype = match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr inline_for_extraction let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) = match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e inline_for_extraction let dsum_key (t: dsum) : Tot Type = maybe_enum_key (dsum_enum t) inline_for_extraction let dsum_known_key (t: dsum) : Tot Type = enum_key (dsum_enum t) inline_for_extraction let dsum_unknown_key (t: dsum) : Tot Type = unknown_enum_repr (dsum_enum t) inline_for_extraction let dsum_type (t: dsum) : Tot Type = //NS: this was rewritten from `let DSum ... data .. = t in data` //to workaround a glitch in desugaring the above, which introduces //an additional, unreduced let binding for extraction match t with | DSum _ _ _ data _ _ _ _ _ _ _ -> data inline_for_extraction let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) = match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data inline_for_extraction let dsum_cases (t: dsum) (x: dsum_key t) : Type = refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x inline_for_extraction let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) = match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) -> type_of_known_tag inline_for_extraction let dsum_type_of_unknown_tag (t: dsum) : Tot Type = match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) -> type_of_unknown_tag inline_for_extraction let dsum_type_of_tag (t: dsum) = dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t) let weaken_parse_dsum_cases_kind (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k' : parser_kind) : Tot parser_kind = let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) -> if List.Tot.mem x keys then let (| k, _ |) = f x in k else k' ) (List.Tot.map fst (dsum_enum s)) `glb` k' let weaken_parse_dsum_cases_kind' (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (#k' : parser_kind) (p: parser k' (dsum_type_of_unknown_tag s)) : Tot parser_kind = weaken_parse_dsum_cases_kind s f k' inline_for_extraction let synth_dsum_case (s: dsum) : Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x)) = match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case inline_for_extraction let synth_dsum_case_recip (s: dsum) : Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x)) = match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip let synth_dsum_case_injective (s: dsum) (x: dsum_key s) : Lemma (synth_injective (synth_dsum_case s x)) = let f (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (requires (synth_dsum_case s x y1 == synth_dsum_case s x y2)) (ensures (y1 == y2)) = let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) = DSum?.synth_case_recip_synth_case s x y1 in let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) = DSum?.synth_case_recip_synth_case s x y2 in // FIXME: WHY WHY WHY is this assert necessary? assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2); () in let g (y1: dsum_type_of_tag s x) (y2: dsum_type_of_tag s x) : Lemma (synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2) = Classical.move_requires (f y1) y2 in Classical.forall_intro_2 g let parse_dsum_type_of_tag (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) | Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x) let parse_dsum_cases (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 (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x)) = synth_dsum_case_injective s x; parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x let parse_dsum_cases_kind (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 parser_kind = match x with | Known k -> dfst (f k) | _ -> k let parse_dsum_type_of_tag' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) = match x with | Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x')) | Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x) let parse_dsum_cases' (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 (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)) = synth_dsum_case_injective s x; match x with | Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) | Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x) let parse_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) (input: bytes) : Lemma (parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input) = synth_dsum_case_injective s x; match x with | Known x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input; parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input | Unknown x' -> parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input; parse_synth_eq g (synth_dsum_case s (Unknown x')) input let parse_dsum' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (#k: parser_kind) (pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x)))) : Tot (parser (and_then_kind kt k) (dsum_type t)) = parse_tagged_union #kt #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) #k pc inline_for_extraction let parse_dsum_kind (kt: parser_kind) (s: dsum) (f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))) (k: parser_kind) : Tot parser_kind = and_then_kind kt (weaken_parse_dsum_cases_kind s f k) let parse_dsum (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k: parser_kind) (g: parser k (dsum_type_of_unknown_tag t)) : Tot (parser (parse_dsum_kind kt t f k) (dsum_type t)) = parse_dsum' t p (parse_dsum_cases t f g) let parse_dsum_eq'' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input; parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input let parse_dsum_eq_ (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input let parse_dsum_eq' (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (k', consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) k' in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_cases' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x) end )) = parse_dsum_eq_ t p f g input; parse_maybe_enum_key_eq p (dsum_enum t) input let parse_dsum_eq (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with | None -> None | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in begin match k with | Known k' -> begin match parse (dsnd (f k')) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end | Unknown k' -> begin match parse g input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end end )) = parse_dsum_eq_ t p f g input; let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in match j with | None -> () | Some (k, consumed_k) -> let input_k = Seq.slice input consumed_k (Seq.length input) in synth_dsum_case_injective t k; begin match k with | Known k_ -> parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k | Unknown k_ -> parse_synth_eq g (synth_dsum_case t k) input_k; parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k end let parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in begin match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x) end
false
false
LowParse.Spec.Sum.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_dsum_eq3 (#kt: parser_kind) (t: dsum) (p: parser kt (dsum_repr_type t)) (f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))) (#k': parser_kind) (g: parser k' (dsum_type_of_unknown_tag t)) (input: bytes) : Lemma (parse (parse_dsum t p f g) input == (match parse p input with | None -> None | Some (r, consumed_k) -> let k = maybe_enum_key_of_repr (dsum_enum t) r in let input_k = Seq.slice input consumed_k (Seq.length input) in match parse (parse_dsum_type_of_tag' t f g k) input_k with | None -> None | Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)))
[]
LowParse.Spec.Sum.parse_dsum_eq3
{ "file_name": "src/lowparse/LowParse.Spec.Sum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: LowParse.Spec.Sum.dsum -> p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) -> f: (x: LowParse.Spec.Sum.dsum_known_key t -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) -> g: LowParse.Spec.Base.parser k' (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum t p f g) input == (match LowParse.Spec.Base.parse p input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ r consumed_k) -> let k = LowParse.Spec.Enum.maybe_enum_key_of_repr (LowParse.Spec.Sum.dsum_enum t) r in let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in (match LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum_type_of_tag' t f g k) input_k with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> FStar.Pervasives.Native.Some (LowParse.Spec.Sum.synth_dsum_case t k x, consumed_k + consumed_x)) <: FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 47, "end_line": 838, "start_col": 2, "start_line": 837 }
Prims.Tot
val set_to_one_LE (q: quad32) : quad32
[ { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_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.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let set_to_one_LE (q:quad32) : quad32 = four_insert q 1 0
val set_to_one_LE (q: quad32) : quad32 let set_to_one_LE (q: quad32) : quad32 =
false
null
false
four_insert q 1 0
{ "checked_file": "Vale.AES.GCM.fsti.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GCM.fsti" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words.Four_s.four_insert", "Vale.Def.Types_s.nat32" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s
false
true
Vale.AES.GCM.fsti
{ "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" }
null
val set_to_one_LE (q: quad32) : quad32
[]
Vale.AES.GCM.set_to_one_LE
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
{ "end_col": 57, "end_line": 20, "start_col": 40, "start_line": 20 }
Prims.Tot
val lower3_equal (q0 q1: quad32) : bool
[ { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_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.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lower3_equal (q0 q1:quad32) : bool = q0.lo0 = q1.lo0 && q0.lo1 = q1.lo1 && q0.hi2 = q1.hi2
val lower3_equal (q0 q1: quad32) : bool let lower3_equal (q0 q1: quad32) : bool =
false
null
false
q0.lo0 = q1.lo0 && q0.lo1 = q1.lo1 && q0.hi2 = q1.hi2
{ "checked_file": "Vale.AES.GCM.fsti.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GCM.fsti" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "Prims.op_AmpAmp", "Prims.op_Equality", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Prims.bool" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let set_to_one_LE (q:quad32) : quad32 = four_insert q 1 0 // Mkfour 1 q.lo1 q.hi2 q.hi3 let upper3_equal (q0 q1:quad32) : bool = q0.lo1 = q1.lo1 && q0.hi2 = q1.hi2 && q0.hi3 = q1.hi3
false
true
Vale.AES.GCM.fsti
{ "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" }
null
val lower3_equal (q0 q1: quad32) : bool
[]
Vale.AES.GCM.lower3_equal
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q0: Vale.Def.Types_s.quad32 -> q1: Vale.Def.Types_s.quad32 -> Prims.bool
{ "end_col": 17, "end_line": 30, "start_col": 2, "start_line": 28 }
Prims.Tot
val upper3_equal (q0 q1: quad32) : bool
[ { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_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.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let upper3_equal (q0 q1:quad32) : bool = q0.lo1 = q1.lo1 && q0.hi2 = q1.hi2 && q0.hi3 = q1.hi3
val upper3_equal (q0 q1: quad32) : bool let upper3_equal (q0 q1: quad32) : bool =
false
null
false
q0.lo1 = q1.lo1 && q0.hi2 = q1.hi2 && q0.hi3 = q1.hi3
{ "checked_file": "Vale.AES.GCM.fsti.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GCM.fsti" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "Prims.op_AmpAmp", "Prims.op_Equality", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Prims.bool" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let set_to_one_LE (q:quad32) : quad32 = four_insert q 1 0 // Mkfour 1 q.lo1 q.hi2 q.hi3
false
true
Vale.AES.GCM.fsti
{ "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" }
null
val upper3_equal (q0 q1: quad32) : bool
[]
Vale.AES.GCM.upper3_equal
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q0: Vale.Def.Types_s.quad32 -> q1: Vale.Def.Types_s.quad32 -> Prims.bool
{ "end_col": 17, "end_line": 25, "start_col": 2, "start_line": 23 }
Prims.Pure
val gcm_decrypt_LE_tag (alg: algorithm) (key: seq nat8) (iv: supported_iv_LE) (cipher auth: seq nat8) : Pure (seq nat8) (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32) (ensures fun t -> True)
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_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.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_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.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let gcm_decrypt_LE_tag (alg:algorithm) (key:seq nat8) (iv:supported_iv_LE) (cipher:seq nat8) (auth:seq nat8) : Pure (seq nat8) (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32 ) (ensures fun t -> True) = let key_LE = seq_nat8_to_seq_nat32_LE key in let h_LE = aes_encrypt_LE alg key_LE (Mkfour 0 0 0 0) in let j0_BE = compute_iv_BE h_LE iv in let lengths_BE = insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length cipher) 0 in let lengths_LE = reverse_bytes_quad32 lengths_BE in let zero_padded_c_LE = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in let zero_padded_a_LE = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let hash_input_LE = append zero_padded_a_LE (append zero_padded_c_LE (create 1 lengths_LE)) in let s_LE = ghash_LE h_LE hash_input_LE in let t = gctr_encrypt_LE j0_BE (le_quad32_to_bytes s_LE) alg key_LE in t
val gcm_decrypt_LE_tag (alg: algorithm) (key: seq nat8) (iv: supported_iv_LE) (cipher auth: seq nat8) : Pure (seq nat8) (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32) (ensures fun t -> True) let gcm_decrypt_LE_tag (alg: algorithm) (key: seq nat8) (iv: supported_iv_LE) (cipher auth: seq nat8) : Pure (seq nat8) (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32) (ensures fun t -> True) =
false
null
false
let key_LE = seq_nat8_to_seq_nat32_LE key in let h_LE = aes_encrypt_LE alg key_LE (Mkfour 0 0 0 0) in let j0_BE = compute_iv_BE h_LE iv in let lengths_BE = insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length cipher) 0 in let lengths_LE = reverse_bytes_quad32 lengths_BE in let zero_padded_c_LE = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in let zero_padded_a_LE = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let hash_input_LE = append zero_padded_a_LE (append zero_padded_c_LE (create 1 lengths_LE)) in let s_LE = ghash_LE h_LE hash_input_LE in let t = gctr_encrypt_LE j0_BE (le_quad32_to_bytes s_LE) alg key_LE in t
{ "checked_file": "Vale.AES.GCM.fsti.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GCM.fsti" }
[]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "Vale.AES.GCM_s.supported_iv_LE", "Vale.AES.GCTR_s.gctr_encrypt_LE", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.Def.Types_s.quad32", "Vale.AES.GHash_s.ghash_LE", "FStar.Seq.Base.append", "FStar.Seq.Base.create", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.Def.Types_s.insert_nat64", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "Vale.AES.GCM_s.compute_iv_BE", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Words_s.nat32", "Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE", "Prims.l_and", "Vale.AES.AES_common_s.is_aes_key", "Prims.b2t", "Prims.op_LessThan", "Vale.Def.Words_s.pow2_32", "Prims.l_True" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let set_to_one_LE (q:quad32) : quad32 = four_insert q 1 0 // Mkfour 1 q.lo1 q.hi2 q.hi3 let upper3_equal (q0 q1:quad32) : bool = q0.lo1 = q1.lo1 && q0.hi2 = q1.hi2 && q0.hi3 = q1.hi3 let lower3_equal (q0 q1:quad32) : bool = q0.lo0 = q1.lo0 && q0.lo1 = q1.lo1 && q0.hi2 = q1.hi2 val lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) open Vale.AES.GHash val lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) val lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma (requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\ (num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\ length s * 16 <= num_bytes /\ num_bytes < length s * 16 + 16 /\ length bytes == 1 ) (ensures slice (le_seq_quad32_to_bytes t) 0 num_bytes == slice (le_seq_quad32_to_bytes (append s bytes)) 0 num_bytes) val gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 p128) p_bytes in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher_raw_quads = append (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) ) val lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_LE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth) ) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag)) val gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes alleged_tag:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 )) (ensures (let plain_raw_quads = append (append p128x6 p128) p_bytes in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher_raw_quads = append (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag))) let gcm_decrypt_LE_tag (alg:algorithm) (key:seq nat8) (iv:supported_iv_LE) (cipher:seq nat8) (auth:seq nat8) : Pure (seq nat8) (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32 )
false
false
Vale.AES.GCM.fsti
{ "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" }
null
val gcm_decrypt_LE_tag (alg: algorithm) (key: seq nat8) (iv: supported_iv_LE) (cipher auth: seq nat8) : Pure (seq nat8) (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32) (ensures fun t -> True)
[]
Vale.AES.GCM.gcm_decrypt_LE_tag
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> iv: Vale.AES.GCM_s.supported_iv_LE -> cipher: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> auth: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> Prims.Pure (FStar.Seq.Base.seq Vale.Def.Words_s.nat8)
{ "end_col": 3, "end_line": 228, "start_col": 3, "start_line": 214 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq16 (a:Type) = seqn 16 a
let seq16 (a: Type) =
false
null
false
seqn 16 a
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "Vale.Def.Words.Seq_s.seqn" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a
false
true
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq16 : a: Type -> Type
[]
Vale.Def.Words.Seq_s.seq16
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Type -> Type
{ "end_col": 30, "end_line": 13, "start_col": 21, "start_line": 13 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq2 (a:Type) = seqn 2 a
let seq2 (a: Type) =
false
null
false
seqn 2 a
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "Vale.Def.Words.Seq_s.seqn" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s
false
true
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq2 : a: Type -> Type
[]
Vale.Def.Words.Seq_s.seq2
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Type -> Type
{ "end_col": 28, "end_line": 10, "start_col": 20, "start_line": 10 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq8 (a:Type) = seqn 8 a
let seq8 (a: Type) =
false
null
false
seqn 8 a
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "Vale.Def.Words.Seq_s.seqn" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a
false
true
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq8 : a: Type -> Type
[]
Vale.Def.Words.Seq_s.seq8
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Type -> Type
{ "end_col": 28, "end_line": 12, "start_col": 20, "start_line": 12 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq4 (a:Type) = seqn 4 a
let seq4 (a: Type) =
false
null
false
seqn 4 a
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "Vale.Def.Words.Seq_s.seqn" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n}
false
true
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq4 : a: Type -> Type
[]
Vale.Def.Words.Seq_s.seq4
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Type -> Type
{ "end_col": 28, "end_line": 11, "start_col": 20, "start_line": 11 }
Prims.Tot
val seq_nat32_to_seq_nat8_BE (x: seq nat32) : seq nat8
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_nat32_to_seq_nat8_BE (x:seq nat32) : seq nat8 = seq_four_to_seq_BE (seq_map (nat_to_four 8) x)
val seq_nat32_to_seq_nat8_BE (x: seq nat32) : seq nat8 let seq_nat32_to_seq_nat8_BE (x: seq nat32) : seq nat8 =
false
null
false
seq_four_to_seq_BE (seq_map (nat_to_four 8) x)
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.Def.Words.Seq_s.seq_four_to_seq_BE", "Vale.Def.Words_s.nat8", "Vale.Lib.Seqs_s.seq_map", "Vale.Def.Words_s.four", "Vale.Def.Words.Four_s.nat_to_four" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1) let seq_to_two_BE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 1) (index s 0) let seq_to_four_LE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 0) (index s 1) (index s 2) (index s 3) let seq_to_four_BE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 3) (index s 2) (index s 1) (index s 0) val two_to_seq_LE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 0 == x.lo /\ index s 1 == x.hi ) val two_to_seq_BE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 1 == x.lo /\ index s 0 == x.hi ) val four_to_seq_LE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 0 == x.lo0 /\ index s 1 == x.lo1 /\ index s 2 == x.hi2 /\ index s 3 == x.hi3 ) val four_to_seq_BE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 3 == x.lo0 /\ index s 2 == x.lo1 /\ index s 1 == x.hi2 /\ index s 0 == x.hi3 ) [@"opaque_to_smt"] let seq_two_to_seq_LE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (n % 2) in init (length x * 2) f [@"opaque_to_smt"] let seq_two_to_seq_BE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (1 - n % 2) in init (length x * 2) f [@"opaque_to_smt"] let seq_four_to_seq_LE (#a:Type) (x:seq (four a)) : (z:seq a{length z == length x * 4}) = let f (n:nat{n < length x * 4}) = four_select (index x (n / 4)) (n % 4) in init (length x * 4) f [@"opaque_to_smt"] let seq_four_to_seq_BE (#a:Type) (x:seq (four a)) : (z:seq a{length z == length x * 4}) = let f (n:nat{n < length x * 4}) = four_select (index x (n / 4)) (3 - n % 4) in init (length x * 4) f [@"opaque_to_smt"] let seq_to_seq_two_LE (#a:Type) (x:seq a{length x % 2 == 0}) : (z:seq (two a){length z == length x / 2}) = let f (n:nat{n < length x / 2}) = Mktwo (index x (n * 2)) (index x (n * 2 + 1)) in init (length x / 2) f [@"opaque_to_smt"] let seq_to_seq_two_BE (#a:Type) (x:seq a{length x % 2 == 0}) : (z:seq (two a){length z == length x / 2}) = let f (n:nat{n < length x / 2}) = Mktwo (index x (n * 2 + 1)) (index x (n * 2)) in init (length x / 2) f [@"opaque_to_smt"] let seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) : (z:seq (four a){length z == length x / 4}) = let f (n:nat{n < length x / 4}) = Mkfour (index x (n * 4)) (index x (n * 4 + 1)) (index x (n * 4 + 2)) (index x (n * 4 + 3)) in init (length x / 4) f [@"opaque_to_smt"] let seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) : (z:seq (four a){length z == length x / 4}) = let f (n:nat{n < length x / 4}) = Mkfour (index x (n * 4 + 3)) (index x (n * 4 + 2)) (index x (n * 4 + 1)) (index x (n * 4)) in init (length x / 4) f // Commonly used operations on bytes let seq_nat8_to_seq_nat32_LE (x:seq nat8{length x % 4 == 0}) : seq nat32 = seq_map (four_to_nat 8) (seq_to_seq_four_LE x) let seq_nat8_to_seq_nat32_BE (x:seq nat8{length x % 4 == 0}) : seq nat32 = seq_map (four_to_nat 8) (seq_to_seq_four_BE x) let seq_nat32_to_seq_nat8_LE (x:seq nat32) : seq nat8 = seq_four_to_seq_LE (seq_map (nat_to_four 8) x)
false
true
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_nat32_to_seq_nat8_BE (x: seq nat32) : seq nat8
[]
Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> FStar.Seq.Base.seq Vale.Def.Words_s.nat8
{ "end_col": 48, "end_line": 116, "start_col": 2, "start_line": 116 }
Prims.Tot
val seq_nat8_to_seq_nat32_LE (x: seq nat8 {length x % 4 == 0}) : seq nat32
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_nat8_to_seq_nat32_LE (x:seq nat8{length x % 4 == 0}) : seq nat32 = seq_map (four_to_nat 8) (seq_to_seq_four_LE x)
val seq_nat8_to_seq_nat32_LE (x: seq nat8 {length x % 4 == 0}) : seq nat32 let seq_nat8_to_seq_nat32_LE (x: seq nat8 {length x % 4 == 0}) : seq nat32 =
false
null
false
seq_map (four_to_nat 8) (seq_to_seq_four_LE x)
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Seq.Base.length", "Vale.Lib.Seqs_s.seq_map", "Vale.Def.Words_s.four", "Vale.Def.Words_s.nat32", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Seq_s.seq_to_seq_four_LE" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1) let seq_to_two_BE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 1) (index s 0) let seq_to_four_LE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 0) (index s 1) (index s 2) (index s 3) let seq_to_four_BE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 3) (index s 2) (index s 1) (index s 0) val two_to_seq_LE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 0 == x.lo /\ index s 1 == x.hi ) val two_to_seq_BE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 1 == x.lo /\ index s 0 == x.hi ) val four_to_seq_LE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 0 == x.lo0 /\ index s 1 == x.lo1 /\ index s 2 == x.hi2 /\ index s 3 == x.hi3 ) val four_to_seq_BE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 3 == x.lo0 /\ index s 2 == x.lo1 /\ index s 1 == x.hi2 /\ index s 0 == x.hi3 ) [@"opaque_to_smt"] let seq_two_to_seq_LE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (n % 2) in init (length x * 2) f [@"opaque_to_smt"] let seq_two_to_seq_BE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (1 - n % 2) in init (length x * 2) f [@"opaque_to_smt"] let seq_four_to_seq_LE (#a:Type) (x:seq (four a)) : (z:seq a{length z == length x * 4}) = let f (n:nat{n < length x * 4}) = four_select (index x (n / 4)) (n % 4) in init (length x * 4) f [@"opaque_to_smt"] let seq_four_to_seq_BE (#a:Type) (x:seq (four a)) : (z:seq a{length z == length x * 4}) = let f (n:nat{n < length x * 4}) = four_select (index x (n / 4)) (3 - n % 4) in init (length x * 4) f [@"opaque_to_smt"] let seq_to_seq_two_LE (#a:Type) (x:seq a{length x % 2 == 0}) : (z:seq (two a){length z == length x / 2}) = let f (n:nat{n < length x / 2}) = Mktwo (index x (n * 2)) (index x (n * 2 + 1)) in init (length x / 2) f [@"opaque_to_smt"] let seq_to_seq_two_BE (#a:Type) (x:seq a{length x % 2 == 0}) : (z:seq (two a){length z == length x / 2}) = let f (n:nat{n < length x / 2}) = Mktwo (index x (n * 2 + 1)) (index x (n * 2)) in init (length x / 2) f [@"opaque_to_smt"] let seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) : (z:seq (four a){length z == length x / 4}) = let f (n:nat{n < length x / 4}) = Mkfour (index x (n * 4)) (index x (n * 4 + 1)) (index x (n * 4 + 2)) (index x (n * 4 + 3)) in init (length x / 4) f [@"opaque_to_smt"] let seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) : (z:seq (four a){length z == length x / 4}) = let f (n:nat{n < length x / 4}) = Mkfour (index x (n * 4 + 3)) (index x (n * 4 + 2)) (index x (n * 4 + 1)) (index x (n * 4)) in init (length x / 4) f // Commonly used operations on bytes
false
false
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_nat8_to_seq_nat32_LE (x: seq nat8 {length x % 4 == 0}) : seq nat32
[]
Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length x % 4 == 0} -> FStar.Seq.Base.seq Vale.Def.Words_s.nat32
{ "end_col": 48, "end_line": 107, "start_col": 2, "start_line": 107 }
Prims.Tot
val seq_nat8_to_seq_nat32_BE (x: seq nat8 {length x % 4 == 0}) : seq nat32
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_nat8_to_seq_nat32_BE (x:seq nat8{length x % 4 == 0}) : seq nat32 = seq_map (four_to_nat 8) (seq_to_seq_four_BE x)
val seq_nat8_to_seq_nat32_BE (x: seq nat8 {length x % 4 == 0}) : seq nat32 let seq_nat8_to_seq_nat32_BE (x: seq nat8 {length x % 4 == 0}) : seq nat32 =
false
null
false
seq_map (four_to_nat 8) (seq_to_seq_four_BE x)
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Seq.Base.length", "Vale.Lib.Seqs_s.seq_map", "Vale.Def.Words_s.four", "Vale.Def.Words_s.nat32", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Seq_s.seq_to_seq_four_BE" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1) let seq_to_two_BE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 1) (index s 0) let seq_to_four_LE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 0) (index s 1) (index s 2) (index s 3) let seq_to_four_BE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 3) (index s 2) (index s 1) (index s 0) val two_to_seq_LE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 0 == x.lo /\ index s 1 == x.hi ) val two_to_seq_BE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 1 == x.lo /\ index s 0 == x.hi ) val four_to_seq_LE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 0 == x.lo0 /\ index s 1 == x.lo1 /\ index s 2 == x.hi2 /\ index s 3 == x.hi3 ) val four_to_seq_BE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 3 == x.lo0 /\ index s 2 == x.lo1 /\ index s 1 == x.hi2 /\ index s 0 == x.hi3 ) [@"opaque_to_smt"] let seq_two_to_seq_LE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (n % 2) in init (length x * 2) f [@"opaque_to_smt"] let seq_two_to_seq_BE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (1 - n % 2) in init (length x * 2) f [@"opaque_to_smt"] let seq_four_to_seq_LE (#a:Type) (x:seq (four a)) : (z:seq a{length z == length x * 4}) = let f (n:nat{n < length x * 4}) = four_select (index x (n / 4)) (n % 4) in init (length x * 4) f [@"opaque_to_smt"] let seq_four_to_seq_BE (#a:Type) (x:seq (four a)) : (z:seq a{length z == length x * 4}) = let f (n:nat{n < length x * 4}) = four_select (index x (n / 4)) (3 - n % 4) in init (length x * 4) f [@"opaque_to_smt"] let seq_to_seq_two_LE (#a:Type) (x:seq a{length x % 2 == 0}) : (z:seq (two a){length z == length x / 2}) = let f (n:nat{n < length x / 2}) = Mktwo (index x (n * 2)) (index x (n * 2 + 1)) in init (length x / 2) f [@"opaque_to_smt"] let seq_to_seq_two_BE (#a:Type) (x:seq a{length x % 2 == 0}) : (z:seq (two a){length z == length x / 2}) = let f (n:nat{n < length x / 2}) = Mktwo (index x (n * 2 + 1)) (index x (n * 2)) in init (length x / 2) f [@"opaque_to_smt"] let seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) : (z:seq (four a){length z == length x / 4}) = let f (n:nat{n < length x / 4}) = Mkfour (index x (n * 4)) (index x (n * 4 + 1)) (index x (n * 4 + 2)) (index x (n * 4 + 3)) in init (length x / 4) f [@"opaque_to_smt"] let seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) : (z:seq (four a){length z == length x / 4}) = let f (n:nat{n < length x / 4}) = Mkfour (index x (n * 4 + 3)) (index x (n * 4 + 2)) (index x (n * 4 + 1)) (index x (n * 4)) in init (length x / 4) f // Commonly used operations on bytes let seq_nat8_to_seq_nat32_LE (x:seq nat8{length x % 4 == 0}) : seq nat32 = seq_map (four_to_nat 8) (seq_to_seq_four_LE x)
false
false
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_nat8_to_seq_nat32_BE (x: seq nat8 {length x % 4 == 0}) : seq nat32
[]
Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_BE
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length x % 4 == 0} -> FStar.Seq.Base.seq Vale.Def.Words_s.nat32
{ "end_col": 48, "end_line": 110, "start_col": 2, "start_line": 110 }
Prims.Tot
val seq_nat32_to_seq_nat8_LE (x: seq nat32) : seq nat8
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_nat32_to_seq_nat8_LE (x:seq nat32) : seq nat8 = seq_four_to_seq_LE (seq_map (nat_to_four 8) x)
val seq_nat32_to_seq_nat8_LE (x: seq nat32) : seq nat8 let seq_nat32_to_seq_nat8_LE (x: seq nat32) : seq nat8 =
false
null
false
seq_four_to_seq_LE (seq_map (nat_to_four 8) x)
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.Def.Words.Seq_s.seq_four_to_seq_LE", "Vale.Def.Words_s.nat8", "Vale.Lib.Seqs_s.seq_map", "Vale.Def.Words_s.four", "Vale.Def.Words.Four_s.nat_to_four" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1) let seq_to_two_BE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 1) (index s 0) let seq_to_four_LE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 0) (index s 1) (index s 2) (index s 3) let seq_to_four_BE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 3) (index s 2) (index s 1) (index s 0) val two_to_seq_LE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 0 == x.lo /\ index s 1 == x.hi ) val two_to_seq_BE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 1 == x.lo /\ index s 0 == x.hi ) val four_to_seq_LE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 0 == x.lo0 /\ index s 1 == x.lo1 /\ index s 2 == x.hi2 /\ index s 3 == x.hi3 ) val four_to_seq_BE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 3 == x.lo0 /\ index s 2 == x.lo1 /\ index s 1 == x.hi2 /\ index s 0 == x.hi3 ) [@"opaque_to_smt"] let seq_two_to_seq_LE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (n % 2) in init (length x * 2) f [@"opaque_to_smt"] let seq_two_to_seq_BE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (1 - n % 2) in init (length x * 2) f [@"opaque_to_smt"] let seq_four_to_seq_LE (#a:Type) (x:seq (four a)) : (z:seq a{length z == length x * 4}) = let f (n:nat{n < length x * 4}) = four_select (index x (n / 4)) (n % 4) in init (length x * 4) f [@"opaque_to_smt"] let seq_four_to_seq_BE (#a:Type) (x:seq (four a)) : (z:seq a{length z == length x * 4}) = let f (n:nat{n < length x * 4}) = four_select (index x (n / 4)) (3 - n % 4) in init (length x * 4) f [@"opaque_to_smt"] let seq_to_seq_two_LE (#a:Type) (x:seq a{length x % 2 == 0}) : (z:seq (two a){length z == length x / 2}) = let f (n:nat{n < length x / 2}) = Mktwo (index x (n * 2)) (index x (n * 2 + 1)) in init (length x / 2) f [@"opaque_to_smt"] let seq_to_seq_two_BE (#a:Type) (x:seq a{length x % 2 == 0}) : (z:seq (two a){length z == length x / 2}) = let f (n:nat{n < length x / 2}) = Mktwo (index x (n * 2 + 1)) (index x (n * 2)) in init (length x / 2) f [@"opaque_to_smt"] let seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) : (z:seq (four a){length z == length x / 4}) = let f (n:nat{n < length x / 4}) = Mkfour (index x (n * 4)) (index x (n * 4 + 1)) (index x (n * 4 + 2)) (index x (n * 4 + 3)) in init (length x / 4) f [@"opaque_to_smt"] let seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) : (z:seq (four a){length z == length x / 4}) = let f (n:nat{n < length x / 4}) = Mkfour (index x (n * 4 + 3)) (index x (n * 4 + 2)) (index x (n * 4 + 1)) (index x (n * 4)) in init (length x / 4) f // Commonly used operations on bytes let seq_nat8_to_seq_nat32_LE (x:seq nat8{length x % 4 == 0}) : seq nat32 = seq_map (four_to_nat 8) (seq_to_seq_four_LE x) let seq_nat8_to_seq_nat32_BE (x:seq nat8{length x % 4 == 0}) : seq nat32 = seq_map (four_to_nat 8) (seq_to_seq_four_BE x)
false
true
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_nat32_to_seq_nat8_LE (x: seq nat32) : seq nat8
[]
Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> FStar.Seq.Base.seq Vale.Def.Words_s.nat8
{ "end_col": 48, "end_line": 113, "start_col": 2, "start_line": 113 }
Prims.Tot
val seq_to_two_LE (#a: Type) (s: seq2 a) : two a
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1)
val seq_to_two_LE (#a: Type) (s: seq2 a) : two a let seq_to_two_LE (#a: Type) (s: seq2 a) : two a =
false
null
false
Mktwo (index s 0) (index s 1)
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "Vale.Def.Words.Seq_s.seq2", "Vale.Def.Words_s.Mktwo", "FStar.Seq.Base.index", "Vale.Def.Words_s.two" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a
false
false
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_to_two_LE (#a: Type) (s: seq2 a) : two a
[]
Vale.Def.Words.Seq_s.seq_to_two_LE
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.Def.Words.Seq_s.seq2 a -> Vale.Def.Words_s.two a
{ "end_col": 31, "end_line": 16, "start_col": 2, "start_line": 16 }
Prims.Tot
val seq_to_two_BE (#a: Type) (s: seq2 a) : two a
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_to_two_BE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 1) (index s 0)
val seq_to_two_BE (#a: Type) (s: seq2 a) : two a let seq_to_two_BE (#a: Type) (s: seq2 a) : two a =
false
null
false
Mktwo (index s 1) (index s 0)
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "Vale.Def.Words.Seq_s.seq2", "Vale.Def.Words_s.Mktwo", "FStar.Seq.Base.index", "Vale.Def.Words_s.two" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1)
false
false
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_to_two_BE (#a: Type) (s: seq2 a) : two a
[]
Vale.Def.Words.Seq_s.seq_to_two_BE
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.Def.Words.Seq_s.seq2 a -> Vale.Def.Words_s.two a
{ "end_col": 31, "end_line": 19, "start_col": 2, "start_line": 19 }
Prims.Tot
val seq_to_four_BE (#a: Type) (s: seq4 a) : four a
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_to_four_BE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 3) (index s 2) (index s 1) (index s 0)
val seq_to_four_BE (#a: Type) (s: seq4 a) : four a let seq_to_four_BE (#a: Type) (s: seq4 a) : four a =
false
null
false
Mkfour (index s 3) (index s 2) (index s 1) (index s 0)
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "Vale.Def.Words.Seq_s.seq4", "Vale.Def.Words_s.Mkfour", "FStar.Seq.Base.index", "Vale.Def.Words_s.four" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1) let seq_to_two_BE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 1) (index s 0) let seq_to_four_LE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 0) (index s 1) (index s 2) (index s 3)
false
false
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_to_four_BE (#a: Type) (s: seq4 a) : four a
[]
Vale.Def.Words.Seq_s.seq_to_four_BE
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.Def.Words.Seq_s.seq4 a -> Vale.Def.Words_s.four a
{ "end_col": 56, "end_line": 25, "start_col": 2, "start_line": 25 }
Prims.Tot
val seq_to_four_LE (#a: Type) (s: seq4 a) : four a
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_to_four_LE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 0) (index s 1) (index s 2) (index s 3)
val seq_to_four_LE (#a: Type) (s: seq4 a) : four a let seq_to_four_LE (#a: Type) (s: seq4 a) : four a =
false
null
false
Mkfour (index s 0) (index s 1) (index s 2) (index s 3)
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "Vale.Def.Words.Seq_s.seq4", "Vale.Def.Words_s.Mkfour", "FStar.Seq.Base.index", "Vale.Def.Words_s.four" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1) let seq_to_two_BE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 1) (index s 0)
false
false
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_to_four_LE (#a: Type) (s: seq4 a) : four a
[]
Vale.Def.Words.Seq_s.seq_to_four_LE
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.Def.Words.Seq_s.seq4 a -> Vale.Def.Words_s.four a
{ "end_col": 56, "end_line": 22, "start_col": 2, "start_line": 22 }
Prims.Tot
val seq_two_to_seq_BE (#a: Type) (x: seq (two a)) : (z: seq a {length z == length x * 2})
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_two_to_seq_BE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (1 - n % 2) in init (length x * 2) f
val seq_two_to_seq_BE (#a: Type) (x: seq (two a)) : (z: seq a {length z == length x * 2}) let seq_two_to_seq_BE (#a: Type) (x: seq (two a)) : (z: seq a {length z == length x * 2}) =
false
null
false
let f (n: nat{n < length x * 2}) = two_select (index x (n / 2)) (1 - n % 2) in init (length x * 2) f
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Words_s.two", "FStar.Seq.Base.init", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Multiply", "Vale.Def.Words.Two_s.two_select", "FStar.Seq.Base.index", "Prims.op_Division", "Prims.op_Subtraction", "Prims.op_Modulus", "Prims.eq2", "Prims.int" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1) let seq_to_two_BE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 1) (index s 0) let seq_to_four_LE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 0) (index s 1) (index s 2) (index s 3) let seq_to_four_BE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 3) (index s 2) (index s 1) (index s 0) val two_to_seq_LE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 0 == x.lo /\ index s 1 == x.hi ) val two_to_seq_BE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 1 == x.lo /\ index s 0 == x.hi ) val four_to_seq_LE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 0 == x.lo0 /\ index s 1 == x.lo1 /\ index s 2 == x.hi2 /\ index s 3 == x.hi3 ) val four_to_seq_BE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 3 == x.lo0 /\ index s 2 == x.lo1 /\ index s 1 == x.hi2 /\ index s 0 == x.hi3 ) [@"opaque_to_smt"] let seq_two_to_seq_LE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (n % 2) in init (length x * 2) f
false
false
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_two_to_seq_BE (#a: Type) (x: seq (two a)) : (z: seq a {length z == length x * 2})
[]
Vale.Def.Words.Seq_s.seq_two_to_seq_BE
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: FStar.Seq.Base.seq (Vale.Def.Words_s.two a) -> z: FStar.Seq.Base.seq a {FStar.Seq.Base.length z == FStar.Seq.Base.length x * 2}
{ "end_col": 23, "end_line": 67, "start_col": 87, "start_line": 65 }
Prims.Tot
val seq_nat8_to_seq_uint8 (x: seq nat8) : seq UInt8.t
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_nat8_to_seq_uint8 (x:seq nat8) : seq UInt8.t = seq_map UInt8.uint_to_t x
val seq_nat8_to_seq_uint8 (x: seq nat8) : seq UInt8.t let seq_nat8_to_seq_uint8 (x: seq nat8) : seq UInt8.t =
false
null
false
seq_map UInt8.uint_to_t x
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "Vale.Lib.Seqs_s.seq_map", "FStar.UInt8.t", "FStar.UInt8.uint_to_t" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1) let seq_to_two_BE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 1) (index s 0) let seq_to_four_LE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 0) (index s 1) (index s 2) (index s 3) let seq_to_four_BE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 3) (index s 2) (index s 1) (index s 0) val two_to_seq_LE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 0 == x.lo /\ index s 1 == x.hi ) val two_to_seq_BE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 1 == x.lo /\ index s 0 == x.hi ) val four_to_seq_LE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 0 == x.lo0 /\ index s 1 == x.lo1 /\ index s 2 == x.hi2 /\ index s 3 == x.hi3 ) val four_to_seq_BE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 3 == x.lo0 /\ index s 2 == x.lo1 /\ index s 1 == x.hi2 /\ index s 0 == x.hi3 ) [@"opaque_to_smt"] let seq_two_to_seq_LE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (n % 2) in init (length x * 2) f [@"opaque_to_smt"] let seq_two_to_seq_BE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (1 - n % 2) in init (length x * 2) f [@"opaque_to_smt"] let seq_four_to_seq_LE (#a:Type) (x:seq (four a)) : (z:seq a{length z == length x * 4}) = let f (n:nat{n < length x * 4}) = four_select (index x (n / 4)) (n % 4) in init (length x * 4) f [@"opaque_to_smt"] let seq_four_to_seq_BE (#a:Type) (x:seq (four a)) : (z:seq a{length z == length x * 4}) = let f (n:nat{n < length x * 4}) = four_select (index x (n / 4)) (3 - n % 4) in init (length x * 4) f [@"opaque_to_smt"] let seq_to_seq_two_LE (#a:Type) (x:seq a{length x % 2 == 0}) : (z:seq (two a){length z == length x / 2}) = let f (n:nat{n < length x / 2}) = Mktwo (index x (n * 2)) (index x (n * 2 + 1)) in init (length x / 2) f [@"opaque_to_smt"] let seq_to_seq_two_BE (#a:Type) (x:seq a{length x % 2 == 0}) : (z:seq (two a){length z == length x / 2}) = let f (n:nat{n < length x / 2}) = Mktwo (index x (n * 2 + 1)) (index x (n * 2)) in init (length x / 2) f [@"opaque_to_smt"] let seq_to_seq_four_LE (#a:Type) (x:seq a{length x % 4 == 0}) : (z:seq (four a){length z == length x / 4}) = let f (n:nat{n < length x / 4}) = Mkfour (index x (n * 4)) (index x (n * 4 + 1)) (index x (n * 4 + 2)) (index x (n * 4 + 3)) in init (length x / 4) f [@"opaque_to_smt"] let seq_to_seq_four_BE (#a:Type) (x:seq a{length x % 4 == 0}) : (z:seq (four a){length z == length x / 4}) = let f (n:nat{n < length x / 4}) = Mkfour (index x (n * 4 + 3)) (index x (n * 4 + 2)) (index x (n * 4 + 1)) (index x (n * 4)) in init (length x / 4) f // Commonly used operations on bytes let seq_nat8_to_seq_nat32_LE (x:seq nat8{length x % 4 == 0}) : seq nat32 = seq_map (four_to_nat 8) (seq_to_seq_four_LE x) let seq_nat8_to_seq_nat32_BE (x:seq nat8{length x % 4 == 0}) : seq nat32 = seq_map (four_to_nat 8) (seq_to_seq_four_BE x) let seq_nat32_to_seq_nat8_LE (x:seq nat32) : seq nat8 = seq_four_to_seq_LE (seq_map (nat_to_four 8) x) let seq_nat32_to_seq_nat8_BE (x:seq nat32) : seq nat8 = seq_four_to_seq_BE (seq_map (nat_to_four 8) x)
false
true
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_nat8_to_seq_uint8 (x: seq nat8) : seq UInt8.t
[]
Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> FStar.Seq.Base.seq FStar.UInt8.t
{ "end_col": 27, "end_line": 119, "start_col": 2, "start_line": 119 }
Prims.Tot
val seq_two_to_seq_LE (#a: Type) (x: seq (two a)) : (z: seq a {length z == length x * 2})
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_two_to_seq_LE (#a:Type) (x:seq (two a)) : (z:seq a{length z == length x * 2}) = let f (n:nat{n < length x * 2}) = two_select (index x (n / 2)) (n % 2) in init (length x * 2) f
val seq_two_to_seq_LE (#a: Type) (x: seq (two a)) : (z: seq a {length z == length x * 2}) let seq_two_to_seq_LE (#a: Type) (x: seq (two a)) : (z: seq a {length z == length x * 2}) =
false
null
false
let f (n: nat{n < length x * 2}) = two_select (index x (n / 2)) (n % 2) in init (length x * 2) f
{ "checked_file": "Vale.Def.Words.Seq_s.fsti.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Def.Words.Seq_s.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Words_s.two", "FStar.Seq.Base.init", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Multiply", "Vale.Def.Words.Two_s.two_select", "FStar.Seq.Base.index", "Prims.op_Division", "Prims.op_Modulus", "Prims.eq2", "Prims.int" ]
[]
module Vale.Def.Words.Seq_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open FStar.Seq open FStar.Mul open Vale.Lib.Seqs_s let seqn (n:nat) (a:Type) : Type = s:seq a{length s == n} let seq2 (a:Type) = seqn 2 a let seq4 (a:Type) = seqn 4 a let seq8 (a:Type) = seqn 8 a let seq16 (a:Type) = seqn 16 a let seq_to_two_LE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 0) (index s 1) let seq_to_two_BE (#a:Type) (s:seq2 a) : two a = Mktwo (index s 1) (index s 0) let seq_to_four_LE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 0) (index s 1) (index s 2) (index s 3) let seq_to_four_BE (#a:Type) (s:seq4 a) : four a = Mkfour (index s 3) (index s 2) (index s 1) (index s 0) val two_to_seq_LE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 0 == x.lo /\ index s 1 == x.hi ) val two_to_seq_BE (#a:Type) (x:two a) : Pure (seq2 a) (requires True) (ensures fun s -> index s 1 == x.lo /\ index s 0 == x.hi ) val four_to_seq_LE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 0 == x.lo0 /\ index s 1 == x.lo1 /\ index s 2 == x.hi2 /\ index s 3 == x.hi3 ) val four_to_seq_BE (#a:Type) (x:four a) : Pure (seq4 a) (requires True) (ensures fun s -> index s 3 == x.lo0 /\ index s 2 == x.lo1 /\ index s 1 == x.hi2 /\ index s 0 == x.hi3 )
false
false
Vale.Def.Words.Seq_s.fsti
{ "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" }
null
val seq_two_to_seq_LE (#a: Type) (x: seq (two a)) : (z: seq a {length z == length x * 2})
[]
Vale.Def.Words.Seq_s.seq_two_to_seq_LE
{ "file_name": "vale/specs/defs/Vale.Def.Words.Seq_s.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: FStar.Seq.Base.seq (Vale.Def.Words_s.two a) -> z: FStar.Seq.Base.seq a {FStar.Seq.Base.length z == FStar.Seq.Base.length x * 2}
{ "end_col": 23, "end_line": 62, "start_col": 87, "start_line": 60 }