file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.effect_annot_to_string | val effect_annot_to_string (e:effect_annot) : T.Tac string | val effect_annot_to_string (e:effect_annot) : T.Tac string | let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens) | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 81,
"end_line": 191,
"start_col": 0,
"start_line": 188
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral" | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: Pulse.Syntax.Base.effect_annot -> FStar.Tactics.Effect.Tac Prims.string | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Syntax.Base.effect_annot",
"Prims.string",
"Pulse.Syntax.Base.term",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.term_to_string"
] | [] | false | true | false | false | false | let effect_annot_to_string =
| function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens = opens } -> sprintf "stt_atomic %s" (term_to_string opens) | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.observability_to_string | val observability_to_string (obs:observability) : string | val observability_to_string (obs:observability) : string | let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral" | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 186,
"start_col": 0,
"start_line": 182
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost" | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | obs: Pulse.Syntax.Base.observability -> Prims.string | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.observability",
"Prims.string"
] | [] | false | false | false | true | false | let observability_to_string =
| function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral" | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.tag_of_term | val tag_of_term (t:term) : string | val tag_of_term (t:term) : string | let tag_of_term (t:term) =
match t.t with
| Tm_Emp -> "Tm_Emp"
| Tm_Pure _ -> "Tm_Pure"
| Tm_Star _ _ -> "Tm_Star"
| Tm_ExistsSL _ _ _ -> "Tm_ExistsSL"
| Tm_ForallSL _ _ _ -> "Tm_ForallSL"
| Tm_VProp -> "Tm_VProp"
| Tm_Inames -> "Tm_Inames"
| Tm_EmpInames -> "Tm_EmpInames"
| Tm_Unknown -> "Tm_Unknown"
| Tm_FStar _ -> "Tm_FStar"
| Tm_AddInv _ _ -> "Tm_AddInv"
| Tm_Inv _ -> "Tm_Inv" | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 447,
"start_col": 0,
"start_line": 434
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral"
let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens)
let comp_to_string (c:comp)
: T.Tac string
= match c with
| C_Tot t ->
sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
let term_opt_to_string (t:option term)
: T.Tac string
= match t with
| None -> ""
| Some t -> term_to_string t
let term_list_to_string (sep:string) (t:list term)
: T.Tac string
= String.concat sep (T.map term_to_string t)
let rec st_term_to_string' (level:string) (t:st_term)
: T.Tac string
= match t.term with
| Tm_Return { insert_eq; term } ->
sprintf "return_%s %s"
(if insert_eq then "" else "_noeq")
(term_to_string term)
| Tm_STApp {head; arg_qual; arg } ->
sprintf "(%s%s %s%s)"
(if dbg_printing then "<stapp>" else "")
(term_to_string head)
(qual_to_string arg_qual)
(term_to_string arg)
| Tm_Bind { binder; head; body } ->
// if T.unseal binder.binder_ppname.name = "_"
// then sprintf "%s;\n%s%s"
// (st_term_to_string' level head)
// level
// (st_term_to_string' level body)
// else (
sprintf "let %s = %s;\n%s%s"
(binder_to_string binder)
(st_term_to_string' level head)
level
(st_term_to_string' level body)
// )
| Tm_TotBind { head; binder; body } ->
sprintf "let tot %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string head)
level
(st_term_to_string' level body)
| Tm_Abs { b; q; ascription=c; body } ->
sprintf "(fun (%s%s)\n%s\n ({\n%s%s\n}%s)"
(qual_to_string q)
(binder_to_string b)
(match c.annotated with | None -> "" | Some c -> comp_to_string c)
(indent level)
(st_term_to_string' (indent level) body)
(match c.elaborated with | None -> "" | Some c -> " <: " ^ comp_to_string c)
| Tm_If { b; then_; else_ } ->
sprintf "if (%s)\n%s{\n%s%s\n%s}\n%selse\n%s{\n%s%s\n%s}"
(term_to_string b)
level
(indent level)
(st_term_to_string' (indent level) then_)
level
level
level
(indent level)
(st_term_to_string' (indent level) else_)
level
| Tm_Match {sc; brs} ->
sprintf "match (%s) with %s"
(term_to_string sc)
(branches_to_string brs)
| Tm_IntroPure { p } ->
sprintf "introduce pure (\n%s%s)"
(indent level)
(term_to_string' (indent level) p)
| Tm_ElimExists { p } ->
sprintf "elim_exists %s"
(term_to_string p)
| Tm_IntroExists { p; witnesses } ->
sprintf "introduce\n%s%s\n%swith %s"
(indent level)
(term_to_string' (indent level) p)
level
(term_list_to_string " " witnesses)
| Tm_While { invariant; condition; body } ->
sprintf "while (%s)\n%sinvariant %s\n%s{\n%s%s\n%s}"
(st_term_to_string' level condition)
level
(term_to_string invariant)
level
(indent level)
(st_term_to_string' (indent level) body)
level
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
sprintf "par (<%s> (%s) <%s) (<%s> (%s) <%s)"
(term_to_string pre1)
(st_term_to_string' level body1)
(term_to_string post1)
(term_to_string pre2)
(st_term_to_string' level body2)
(term_to_string post2)
| Tm_Rewrite { t1; t2 } ->
sprintf "rewrite %s %s"
(term_to_string t1)
(term_to_string t2)
| Tm_WithLocal { binder; initializer; body } ->
sprintf "let mut %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
level
(st_term_to_string' level body)
| Tm_WithLocalArray { binder; initializer; length; body } ->
sprintf "let mut %s = [| %s; %s |]\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
(term_to_string length)
level
(st_term_to_string' level body)
| Tm_Admit { ctag; u; typ; post } ->
sprintf "%s<%s> %s%s"
(match ctag with
| STT -> "stt_admit"
| STT_Atomic -> "stt_atomic_admit"
| STT_Ghost -> "stt_ghost_admit")
(universe_to_string 0 u)
(term_to_string typ)
(match post with
| None -> ""
| Some post -> sprintf " %s" (term_to_string post))
| Tm_Unreachable -> "unreachable ()"
| Tm_ProofHintWithBinders { binders; hint_type; t} ->
let with_prefix =
match binders with
| [] -> ""
| _ -> sprintf "with %s." (String.concat " " (T.map binder_to_string binders))
in
let names_to_string = function
| None -> ""
| Some l -> sprintf " [%s]" (String.concat "; " l)
in
let ht, p =
match hint_type with
| ASSERT { p } -> "assert", term_to_string p
| UNFOLD { names; p } -> sprintf "unfold%s" (names_to_string names), term_to_string p
| FOLD { names; p } -> sprintf "fold%s" (names_to_string names), term_to_string p
| RENAME { pairs; goal } ->
sprintf "rewrite each %s"
(String.concat ", "
(T.map
(fun (x, y) -> sprintf "%s as %s" (term_to_string x) (term_to_string y))
pairs)),
(match goal with
| None -> ""
| Some t -> sprintf " in %s" (term_to_string t))
| REWRITE { t1; t2 } ->
sprintf "rewrite %s as %s" (term_to_string t1) (term_to_string t2), ""
| WILD -> "_", ""
| SHOW_PROOF_STATE _ -> "show_proof_state", ""
in
sprintf "%s %s %s; %s" with_prefix ht p
(st_term_to_string' level t)
| Tm_WithInv { name; body; returns_inv } ->
sprintf "with_inv %s %s %s"
(term_to_string name)
(st_term_to_string' level body)
(match returns_inv with
| None -> ""
| Some (b, t) ->
sprintf "\nreturns %s\nensures %s"
(binder_to_string b)
(term_to_string t))
and branches_to_string brs : T.Tac _ =
match brs with
| [] -> ""
| b::bs -> branch_to_string b ^ branches_to_string bs
and branch_to_string br : T.Tac _ =
let (pat, e) = br in
Printf.sprintf "{ %s -> %s }"
(pattern_to_string pat)
(st_term_to_string' "" e)
and pattern_to_string (p:pattern) : T.Tac string =
match p with
| Pat_Cons fv pats ->
Printf.sprintf "(%s %s)"
(String.concat "." fv.fv_name)
(String.concat " " (T.map (fun (p, _) -> pattern_to_string p) pats))
| Pat_Constant c ->
"<constant>"
| Pat_Var x _ ->
T.unseal x
| Pat_Dot_Term None ->
""
| Pat_Dot_Term (Some t) ->
Printf.sprintf "(.??)" //%s)" (term_to_string t)
let st_term_to_string t = st_term_to_string' "" t | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> Prims.string | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.host_term",
"Prims.string"
] | [] | false | false | false | true | false | let tag_of_term (t: term) =
| match t.t with
| Tm_Emp -> "Tm_Emp"
| Tm_Pure _ -> "Tm_Pure"
| Tm_Star _ _ -> "Tm_Star"
| Tm_ExistsSL _ _ _ -> "Tm_ExistsSL"
| Tm_ForallSL _ _ _ -> "Tm_ForallSL"
| Tm_VProp -> "Tm_VProp"
| Tm_Inames -> "Tm_Inames"
| Tm_EmpInames -> "Tm_EmpInames"
| Tm_Unknown -> "Tm_Unknown"
| Tm_FStar _ -> "Tm_FStar"
| Tm_AddInv _ _ -> "Tm_AddInv"
| Tm_Inv _ -> "Tm_Inv" | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.term_opt_to_string | val term_opt_to_string (t: option term) : T.Tac string | val term_opt_to_string (t: option term) : T.Tac string | let term_opt_to_string (t:option term)
: T.Tac string
= match t with
| None -> ""
| Some t -> term_to_string t | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 32,
"end_line": 223,
"start_col": 0,
"start_line": 219
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral"
let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens)
let comp_to_string (c:comp)
: T.Tac string
= match c with
| C_Tot t ->
sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post) | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Pervasives.Native.option Pulse.Syntax.Base.term -> FStar.Tactics.Effect.Tac Prims.string | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.term",
"Prims.string",
"Pulse.Syntax.Printer.term_to_string"
] | [] | false | true | false | false | false | let term_opt_to_string (t: option term) : T.Tac string =
| match t with
| None -> ""
| Some t -> term_to_string t | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.tag_of_st_term | val tag_of_st_term (t:st_term) : string | val tag_of_st_term (t:st_term) : string | let tag_of_st_term (t:st_term) =
match t.term with
| Tm_Return _ -> "Tm_Return"
| Tm_Abs _ -> "Tm_Abs"
| Tm_STApp _ -> "Tm_STApp"
| Tm_Bind _ -> "Tm_Bind"
| Tm_TotBind _ -> "Tm_TotBind"
| Tm_If _ -> "Tm_If"
| Tm_Match _ -> "Tm_Match"
| Tm_IntroPure _ -> "Tm_IntroPure"
| Tm_ElimExists _ -> "Tm_ElimExists"
| Tm_IntroExists _ -> "Tm_IntroExists"
| Tm_While _ -> "Tm_While"
| Tm_Par _ -> "Tm_Par"
| Tm_WithLocal _ -> "Tm_WithLocal"
| Tm_WithLocalArray _ -> "Tm_WithLocalArray"
| Tm_Rewrite _ -> "Tm_Rewrite"
| Tm_Admit _ -> "Tm_Admit"
| Tm_Unreachable -> "Tm_Unreachable"
| Tm_ProofHintWithBinders _ -> "Tm_ProofHintWithBinders"
| Tm_WithInv _ -> "Tm_WithInv" | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 32,
"end_line": 469,
"start_col": 0,
"start_line": 449
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral"
let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens)
let comp_to_string (c:comp)
: T.Tac string
= match c with
| C_Tot t ->
sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
let term_opt_to_string (t:option term)
: T.Tac string
= match t with
| None -> ""
| Some t -> term_to_string t
let term_list_to_string (sep:string) (t:list term)
: T.Tac string
= String.concat sep (T.map term_to_string t)
let rec st_term_to_string' (level:string) (t:st_term)
: T.Tac string
= match t.term with
| Tm_Return { insert_eq; term } ->
sprintf "return_%s %s"
(if insert_eq then "" else "_noeq")
(term_to_string term)
| Tm_STApp {head; arg_qual; arg } ->
sprintf "(%s%s %s%s)"
(if dbg_printing then "<stapp>" else "")
(term_to_string head)
(qual_to_string arg_qual)
(term_to_string arg)
| Tm_Bind { binder; head; body } ->
// if T.unseal binder.binder_ppname.name = "_"
// then sprintf "%s;\n%s%s"
// (st_term_to_string' level head)
// level
// (st_term_to_string' level body)
// else (
sprintf "let %s = %s;\n%s%s"
(binder_to_string binder)
(st_term_to_string' level head)
level
(st_term_to_string' level body)
// )
| Tm_TotBind { head; binder; body } ->
sprintf "let tot %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string head)
level
(st_term_to_string' level body)
| Tm_Abs { b; q; ascription=c; body } ->
sprintf "(fun (%s%s)\n%s\n ({\n%s%s\n}%s)"
(qual_to_string q)
(binder_to_string b)
(match c.annotated with | None -> "" | Some c -> comp_to_string c)
(indent level)
(st_term_to_string' (indent level) body)
(match c.elaborated with | None -> "" | Some c -> " <: " ^ comp_to_string c)
| Tm_If { b; then_; else_ } ->
sprintf "if (%s)\n%s{\n%s%s\n%s}\n%selse\n%s{\n%s%s\n%s}"
(term_to_string b)
level
(indent level)
(st_term_to_string' (indent level) then_)
level
level
level
(indent level)
(st_term_to_string' (indent level) else_)
level
| Tm_Match {sc; brs} ->
sprintf "match (%s) with %s"
(term_to_string sc)
(branches_to_string brs)
| Tm_IntroPure { p } ->
sprintf "introduce pure (\n%s%s)"
(indent level)
(term_to_string' (indent level) p)
| Tm_ElimExists { p } ->
sprintf "elim_exists %s"
(term_to_string p)
| Tm_IntroExists { p; witnesses } ->
sprintf "introduce\n%s%s\n%swith %s"
(indent level)
(term_to_string' (indent level) p)
level
(term_list_to_string " " witnesses)
| Tm_While { invariant; condition; body } ->
sprintf "while (%s)\n%sinvariant %s\n%s{\n%s%s\n%s}"
(st_term_to_string' level condition)
level
(term_to_string invariant)
level
(indent level)
(st_term_to_string' (indent level) body)
level
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
sprintf "par (<%s> (%s) <%s) (<%s> (%s) <%s)"
(term_to_string pre1)
(st_term_to_string' level body1)
(term_to_string post1)
(term_to_string pre2)
(st_term_to_string' level body2)
(term_to_string post2)
| Tm_Rewrite { t1; t2 } ->
sprintf "rewrite %s %s"
(term_to_string t1)
(term_to_string t2)
| Tm_WithLocal { binder; initializer; body } ->
sprintf "let mut %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
level
(st_term_to_string' level body)
| Tm_WithLocalArray { binder; initializer; length; body } ->
sprintf "let mut %s = [| %s; %s |]\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
(term_to_string length)
level
(st_term_to_string' level body)
| Tm_Admit { ctag; u; typ; post } ->
sprintf "%s<%s> %s%s"
(match ctag with
| STT -> "stt_admit"
| STT_Atomic -> "stt_atomic_admit"
| STT_Ghost -> "stt_ghost_admit")
(universe_to_string 0 u)
(term_to_string typ)
(match post with
| None -> ""
| Some post -> sprintf " %s" (term_to_string post))
| Tm_Unreachable -> "unreachable ()"
| Tm_ProofHintWithBinders { binders; hint_type; t} ->
let with_prefix =
match binders with
| [] -> ""
| _ -> sprintf "with %s." (String.concat " " (T.map binder_to_string binders))
in
let names_to_string = function
| None -> ""
| Some l -> sprintf " [%s]" (String.concat "; " l)
in
let ht, p =
match hint_type with
| ASSERT { p } -> "assert", term_to_string p
| UNFOLD { names; p } -> sprintf "unfold%s" (names_to_string names), term_to_string p
| FOLD { names; p } -> sprintf "fold%s" (names_to_string names), term_to_string p
| RENAME { pairs; goal } ->
sprintf "rewrite each %s"
(String.concat ", "
(T.map
(fun (x, y) -> sprintf "%s as %s" (term_to_string x) (term_to_string y))
pairs)),
(match goal with
| None -> ""
| Some t -> sprintf " in %s" (term_to_string t))
| REWRITE { t1; t2 } ->
sprintf "rewrite %s as %s" (term_to_string t1) (term_to_string t2), ""
| WILD -> "_", ""
| SHOW_PROOF_STATE _ -> "show_proof_state", ""
in
sprintf "%s %s %s; %s" with_prefix ht p
(st_term_to_string' level t)
| Tm_WithInv { name; body; returns_inv } ->
sprintf "with_inv %s %s %s"
(term_to_string name)
(st_term_to_string' level body)
(match returns_inv with
| None -> ""
| Some (b, t) ->
sprintf "\nreturns %s\nensures %s"
(binder_to_string b)
(term_to_string t))
and branches_to_string brs : T.Tac _ =
match brs with
| [] -> ""
| b::bs -> branch_to_string b ^ branches_to_string bs
and branch_to_string br : T.Tac _ =
let (pat, e) = br in
Printf.sprintf "{ %s -> %s }"
(pattern_to_string pat)
(st_term_to_string' "" e)
and pattern_to_string (p:pattern) : T.Tac string =
match p with
| Pat_Cons fv pats ->
Printf.sprintf "(%s %s)"
(String.concat "." fv.fv_name)
(String.concat " " (T.map (fun (p, _) -> pattern_to_string p) pats))
| Pat_Constant c ->
"<constant>"
| Pat_Var x _ ->
T.unseal x
| Pat_Dot_Term None ->
""
| Pat_Dot_Term (Some t) ->
Printf.sprintf "(.??)" //%s)" (term_to_string t)
let st_term_to_string t = st_term_to_string' "" t
let tag_of_term (t:term) =
match t.t with
| Tm_Emp -> "Tm_Emp"
| Tm_Pure _ -> "Tm_Pure"
| Tm_Star _ _ -> "Tm_Star"
| Tm_ExistsSL _ _ _ -> "Tm_ExistsSL"
| Tm_ForallSL _ _ _ -> "Tm_ForallSL"
| Tm_VProp -> "Tm_VProp"
| Tm_Inames -> "Tm_Inames"
| Tm_EmpInames -> "Tm_EmpInames"
| Tm_Unknown -> "Tm_Unknown"
| Tm_FStar _ -> "Tm_FStar"
| Tm_AddInv _ _ -> "Tm_AddInv"
| Tm_Inv _ -> "Tm_Inv" | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.st_term -> Prims.string | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.__proj__Mkst_term__item__term",
"Pulse.Syntax.Base.st_term'__Tm_Return__payload",
"Pulse.Syntax.Base.st_term'__Tm_Abs__payload",
"Pulse.Syntax.Base.st_term'__Tm_STApp__payload",
"Pulse.Syntax.Base.st_term'__Tm_Bind__payload",
"Pulse.Syntax.Base.st_term'__Tm_TotBind__payload",
"Pulse.Syntax.Base.st_term'__Tm_If__payload",
"Pulse.Syntax.Base.st_term'__Tm_Match__payload",
"Pulse.Syntax.Base.st_term'__Tm_IntroPure__payload",
"Pulse.Syntax.Base.st_term'__Tm_ElimExists__payload",
"Pulse.Syntax.Base.st_term'__Tm_IntroExists__payload",
"Pulse.Syntax.Base.st_term'__Tm_While__payload",
"Pulse.Syntax.Base.st_term'__Tm_Par__payload",
"Pulse.Syntax.Base.st_term'__Tm_WithLocal__payload",
"Pulse.Syntax.Base.st_term'__Tm_WithLocalArray__payload",
"Pulse.Syntax.Base.st_term'__Tm_Rewrite__payload",
"Pulse.Syntax.Base.st_term'__Tm_Admit__payload",
"Pulse.Syntax.Base.st_term'__Tm_ProofHintWithBinders__payload",
"Pulse.Syntax.Base.st_term'__Tm_WithInv__payload",
"Prims.string"
] | [] | false | false | false | true | false | let tag_of_st_term (t: st_term) =
| match t.term with
| Tm_Return _ -> "Tm_Return"
| Tm_Abs _ -> "Tm_Abs"
| Tm_STApp _ -> "Tm_STApp"
| Tm_Bind _ -> "Tm_Bind"
| Tm_TotBind _ -> "Tm_TotBind"
| Tm_If _ -> "Tm_If"
| Tm_Match _ -> "Tm_Match"
| Tm_IntroPure _ -> "Tm_IntroPure"
| Tm_ElimExists _ -> "Tm_ElimExists"
| Tm_IntroExists _ -> "Tm_IntroExists"
| Tm_While _ -> "Tm_While"
| Tm_Par _ -> "Tm_Par"
| Tm_WithLocal _ -> "Tm_WithLocal"
| Tm_WithLocalArray _ -> "Tm_WithLocalArray"
| Tm_Rewrite _ -> "Tm_Rewrite"
| Tm_Admit _ -> "Tm_Admit"
| Tm_Unreachable -> "Tm_Unreachable"
| Tm_ProofHintWithBinders _ -> "Tm_ProofHintWithBinders"
| Tm_WithInv _ -> "Tm_WithInv" | false |
Hacl.Impl.RSAPSS.Padding.fst | Hacl.Impl.RSAPSS.Padding.xor_bytes | val xor_bytes:
len:size_t{v len > 0}
-> b1:lbuffer uint8 len
-> b2:lbuffer uint8 len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1) h0 h1 /\
as_seq h1 b1 == S.xor_bytes (as_seq h0 b1) (as_seq h0 b2)) | val xor_bytes:
len:size_t{v len > 0}
-> b1:lbuffer uint8 len
-> b2:lbuffer uint8 len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1) h0 h1 /\
as_seq h1 b1 == S.xor_bytes (as_seq h0 b1) (as_seq h0 b2)) | let xor_bytes len b1 b2 =
map2T len b1 (fun x y -> x ^. y) b1 b2 | {
"file_name": "code/rsapss/Hacl.Impl.RSAPSS.Padding.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 49,
"start_col": 0,
"start_line": 48
} | module Hacl.Impl.RSAPSS.Padding
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.RSAPSS.MGF
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Hash = Spec.Agile.Hash
module S = Spec.RSAPSS
module BD = Hacl.Bignum.Definitions
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let less_than_max_input_length = Spec.Hash.Definitions.less_than_max_input_length
inline_for_extraction noextract
let salt_len_t (a:Hash.fixed_len_alg) =
saltLen:size_t{8 + Hash.hash_length a + v saltLen <= max_size_t /\ (8 + Hash.hash_length a + v saltLen) `less_than_max_input_length` a}
inline_for_extraction noextract
let msg_len_t (a:Hash.fixed_len_alg) =
msgLen:size_t{v msgLen `less_than_max_input_length` a}
inline_for_extraction noextract
let em_len_t (a:Hash.fixed_len_alg) (saltLen:salt_len_t a) =
emBits:size_t{0 < v emBits /\ Hash.hash_length a + v saltLen + 2 <= S.blocks (v emBits) 8}
inline_for_extraction noextract
val xor_bytes:
len:size_t{v len > 0}
-> b1:lbuffer uint8 len
-> b2:lbuffer uint8 len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1) h0 h1 /\
as_seq h1 b1 == S.xor_bytes (as_seq h0 b1) (as_seq h0 b2)) | {
"checked_file": "/",
"dependencies": [
"Spec.RSAPSS.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.RSAPSS.MGF.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.RSAPSS.Padding.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Spec.RSAPSS",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS.MGF",
"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.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
b1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len ->
b2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.Buffer.map2T",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Hat_Dot",
"Prims.unit"
] | [] | false | true | false | false | false | let xor_bytes len b1 b2 =
| map2T len b1 (fun x y -> x ^. y) b1 b2 | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.tag_of_comp | val tag_of_comp (c:comp): T.Tac string | val tag_of_comp (c:comp): T.Tac string | let tag_of_comp (c:comp) : T.Tac string =
match c with
| C_Tot _ -> "Total"
| C_ST _ -> "ST"
| C_STAtomic i obs _ ->
Printf.sprintf "%s %s" (observability_to_string obs) (term_to_string i)
| C_STGhost _ ->
"Ghost" | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 11,
"end_line": 478,
"start_col": 0,
"start_line": 471
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral"
let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens)
let comp_to_string (c:comp)
: T.Tac string
= match c with
| C_Tot t ->
sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
let term_opt_to_string (t:option term)
: T.Tac string
= match t with
| None -> ""
| Some t -> term_to_string t
let term_list_to_string (sep:string) (t:list term)
: T.Tac string
= String.concat sep (T.map term_to_string t)
let rec st_term_to_string' (level:string) (t:st_term)
: T.Tac string
= match t.term with
| Tm_Return { insert_eq; term } ->
sprintf "return_%s %s"
(if insert_eq then "" else "_noeq")
(term_to_string term)
| Tm_STApp {head; arg_qual; arg } ->
sprintf "(%s%s %s%s)"
(if dbg_printing then "<stapp>" else "")
(term_to_string head)
(qual_to_string arg_qual)
(term_to_string arg)
| Tm_Bind { binder; head; body } ->
// if T.unseal binder.binder_ppname.name = "_"
// then sprintf "%s;\n%s%s"
// (st_term_to_string' level head)
// level
// (st_term_to_string' level body)
// else (
sprintf "let %s = %s;\n%s%s"
(binder_to_string binder)
(st_term_to_string' level head)
level
(st_term_to_string' level body)
// )
| Tm_TotBind { head; binder; body } ->
sprintf "let tot %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string head)
level
(st_term_to_string' level body)
| Tm_Abs { b; q; ascription=c; body } ->
sprintf "(fun (%s%s)\n%s\n ({\n%s%s\n}%s)"
(qual_to_string q)
(binder_to_string b)
(match c.annotated with | None -> "" | Some c -> comp_to_string c)
(indent level)
(st_term_to_string' (indent level) body)
(match c.elaborated with | None -> "" | Some c -> " <: " ^ comp_to_string c)
| Tm_If { b; then_; else_ } ->
sprintf "if (%s)\n%s{\n%s%s\n%s}\n%selse\n%s{\n%s%s\n%s}"
(term_to_string b)
level
(indent level)
(st_term_to_string' (indent level) then_)
level
level
level
(indent level)
(st_term_to_string' (indent level) else_)
level
| Tm_Match {sc; brs} ->
sprintf "match (%s) with %s"
(term_to_string sc)
(branches_to_string brs)
| Tm_IntroPure { p } ->
sprintf "introduce pure (\n%s%s)"
(indent level)
(term_to_string' (indent level) p)
| Tm_ElimExists { p } ->
sprintf "elim_exists %s"
(term_to_string p)
| Tm_IntroExists { p; witnesses } ->
sprintf "introduce\n%s%s\n%swith %s"
(indent level)
(term_to_string' (indent level) p)
level
(term_list_to_string " " witnesses)
| Tm_While { invariant; condition; body } ->
sprintf "while (%s)\n%sinvariant %s\n%s{\n%s%s\n%s}"
(st_term_to_string' level condition)
level
(term_to_string invariant)
level
(indent level)
(st_term_to_string' (indent level) body)
level
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
sprintf "par (<%s> (%s) <%s) (<%s> (%s) <%s)"
(term_to_string pre1)
(st_term_to_string' level body1)
(term_to_string post1)
(term_to_string pre2)
(st_term_to_string' level body2)
(term_to_string post2)
| Tm_Rewrite { t1; t2 } ->
sprintf "rewrite %s %s"
(term_to_string t1)
(term_to_string t2)
| Tm_WithLocal { binder; initializer; body } ->
sprintf "let mut %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
level
(st_term_to_string' level body)
| Tm_WithLocalArray { binder; initializer; length; body } ->
sprintf "let mut %s = [| %s; %s |]\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
(term_to_string length)
level
(st_term_to_string' level body)
| Tm_Admit { ctag; u; typ; post } ->
sprintf "%s<%s> %s%s"
(match ctag with
| STT -> "stt_admit"
| STT_Atomic -> "stt_atomic_admit"
| STT_Ghost -> "stt_ghost_admit")
(universe_to_string 0 u)
(term_to_string typ)
(match post with
| None -> ""
| Some post -> sprintf " %s" (term_to_string post))
| Tm_Unreachable -> "unreachable ()"
| Tm_ProofHintWithBinders { binders; hint_type; t} ->
let with_prefix =
match binders with
| [] -> ""
| _ -> sprintf "with %s." (String.concat " " (T.map binder_to_string binders))
in
let names_to_string = function
| None -> ""
| Some l -> sprintf " [%s]" (String.concat "; " l)
in
let ht, p =
match hint_type with
| ASSERT { p } -> "assert", term_to_string p
| UNFOLD { names; p } -> sprintf "unfold%s" (names_to_string names), term_to_string p
| FOLD { names; p } -> sprintf "fold%s" (names_to_string names), term_to_string p
| RENAME { pairs; goal } ->
sprintf "rewrite each %s"
(String.concat ", "
(T.map
(fun (x, y) -> sprintf "%s as %s" (term_to_string x) (term_to_string y))
pairs)),
(match goal with
| None -> ""
| Some t -> sprintf " in %s" (term_to_string t))
| REWRITE { t1; t2 } ->
sprintf "rewrite %s as %s" (term_to_string t1) (term_to_string t2), ""
| WILD -> "_", ""
| SHOW_PROOF_STATE _ -> "show_proof_state", ""
in
sprintf "%s %s %s; %s" with_prefix ht p
(st_term_to_string' level t)
| Tm_WithInv { name; body; returns_inv } ->
sprintf "with_inv %s %s %s"
(term_to_string name)
(st_term_to_string' level body)
(match returns_inv with
| None -> ""
| Some (b, t) ->
sprintf "\nreturns %s\nensures %s"
(binder_to_string b)
(term_to_string t))
and branches_to_string brs : T.Tac _ =
match brs with
| [] -> ""
| b::bs -> branch_to_string b ^ branches_to_string bs
and branch_to_string br : T.Tac _ =
let (pat, e) = br in
Printf.sprintf "{ %s -> %s }"
(pattern_to_string pat)
(st_term_to_string' "" e)
and pattern_to_string (p:pattern) : T.Tac string =
match p with
| Pat_Cons fv pats ->
Printf.sprintf "(%s %s)"
(String.concat "." fv.fv_name)
(String.concat " " (T.map (fun (p, _) -> pattern_to_string p) pats))
| Pat_Constant c ->
"<constant>"
| Pat_Var x _ ->
T.unseal x
| Pat_Dot_Term None ->
""
| Pat_Dot_Term (Some t) ->
Printf.sprintf "(.??)" //%s)" (term_to_string t)
let st_term_to_string t = st_term_to_string' "" t
let tag_of_term (t:term) =
match t.t with
| Tm_Emp -> "Tm_Emp"
| Tm_Pure _ -> "Tm_Pure"
| Tm_Star _ _ -> "Tm_Star"
| Tm_ExistsSL _ _ _ -> "Tm_ExistsSL"
| Tm_ForallSL _ _ _ -> "Tm_ForallSL"
| Tm_VProp -> "Tm_VProp"
| Tm_Inames -> "Tm_Inames"
| Tm_EmpInames -> "Tm_EmpInames"
| Tm_Unknown -> "Tm_Unknown"
| Tm_FStar _ -> "Tm_FStar"
| Tm_AddInv _ _ -> "Tm_AddInv"
| Tm_Inv _ -> "Tm_Inv"
let tag_of_st_term (t:st_term) =
match t.term with
| Tm_Return _ -> "Tm_Return"
| Tm_Abs _ -> "Tm_Abs"
| Tm_STApp _ -> "Tm_STApp"
| Tm_Bind _ -> "Tm_Bind"
| Tm_TotBind _ -> "Tm_TotBind"
| Tm_If _ -> "Tm_If"
| Tm_Match _ -> "Tm_Match"
| Tm_IntroPure _ -> "Tm_IntroPure"
| Tm_ElimExists _ -> "Tm_ElimExists"
| Tm_IntroExists _ -> "Tm_IntroExists"
| Tm_While _ -> "Tm_While"
| Tm_Par _ -> "Tm_Par"
| Tm_WithLocal _ -> "Tm_WithLocal"
| Tm_WithLocalArray _ -> "Tm_WithLocalArray"
| Tm_Rewrite _ -> "Tm_Rewrite"
| Tm_Admit _ -> "Tm_Admit"
| Tm_Unreachable -> "Tm_Unreachable"
| Tm_ProofHintWithBinders _ -> "Tm_ProofHintWithBinders"
| Tm_WithInv _ -> "Tm_WithInv" | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: Pulse.Syntax.Base.comp -> FStar.Tactics.Effect.Tac Prims.string | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"Prims.string",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.observability",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.observability_to_string",
"Pulse.Syntax.Printer.term_to_string"
] | [] | false | true | false | false | false | let tag_of_comp (c: comp) : T.Tac string =
| match c with
| C_Tot _ -> "Total"
| C_ST _ -> "ST"
| C_STAtomic i obs _ -> Printf.sprintf "%s %s" (observability_to_string obs) (term_to_string i)
| C_STGhost _ -> "Ghost" | false |
Vale.AES.X64.GCMdecryptOpt.fst | Vale.AES.X64.GCMdecryptOpt.va_wpProof_Gcm_blocks | val va_wpProof_Gcm_blocks : alg:algorithm -> offset:int -> auth_b:buffer128 -> abytes_b:buffer128
-> in128x6_b:buffer128 -> out128x6_b:buffer128 -> in128_b:buffer128 -> out128_b:buffer128 ->
inout_b:buffer128 -> iv_b:buffer128 -> scratch_b:buffer128 -> key:(seq nat32) -> round_keys:(seq
quad32) -> keys_b:buffer128 -> hkeys_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit ->
Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Gcm_blocks alg offset auth_b abytes_b in128x6_b out128x6_b
in128_b out128_b inout_b iv_b scratch_b key round_keys keys_b hkeys_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gcm_blocks alg offset) ([va_Mod_flags;
va_Mod_mem_heaplet 6; va_Mod_mem_heaplet 5; va_Mod_mem_heaplet 3; va_Mod_mem_heaplet 2;
va_Mod_mem_heaplet 1; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm
11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5;
va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR15;
va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rR10;
va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRbp; va_Mod_reg64 rRsi; va_Mod_reg64 rRdi;
va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_mem]) va_s0
va_k ((va_sM, va_f0, va_g)))) | val va_wpProof_Gcm_blocks : alg:algorithm -> offset:int -> auth_b:buffer128 -> abytes_b:buffer128
-> in128x6_b:buffer128 -> out128x6_b:buffer128 -> in128_b:buffer128 -> out128_b:buffer128 ->
inout_b:buffer128 -> iv_b:buffer128 -> scratch_b:buffer128 -> key:(seq nat32) -> round_keys:(seq
quad32) -> keys_b:buffer128 -> hkeys_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit ->
Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Gcm_blocks alg offset auth_b abytes_b in128x6_b out128x6_b
in128_b out128_b inout_b iv_b scratch_b key round_keys keys_b hkeys_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gcm_blocks alg offset) ([va_Mod_flags;
va_Mod_mem_heaplet 6; va_Mod_mem_heaplet 5; va_Mod_mem_heaplet 3; va_Mod_mem_heaplet 2;
va_Mod_mem_heaplet 1; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm
11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5;
va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR15;
va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rR10;
va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRbp; va_Mod_reg64 rRsi; va_Mod_reg64 rRdi;
va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_mem]) va_s0
va_k ((va_sM, va_f0, va_g)))) | let va_wpProof_Gcm_blocks alg offset auth_b abytes_b in128x6_b out128x6_b in128_b out128_b inout_b
iv_b scratch_b key round_keys keys_b hkeys_b va_s0 va_k =
let (va_sM, va_f0) = va_lemma_Gcm_blocks (va_code_Gcm_blocks alg offset) va_s0 alg offset auth_b
abytes_b in128x6_b out128x6_b in128_b out128_b inout_b iv_b scratch_b key round_keys keys_b
hkeys_b in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_flags va_sM (va_update_mem_heaplet 6 va_sM
(va_update_mem_heaplet 5 va_sM (va_update_mem_heaplet 3 va_sM (va_update_mem_heaplet 2 va_sM
(va_update_mem_heaplet 1 va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm
13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm
9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5
va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM
(va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM
(va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM
(va_update_reg64 rRbp va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdi va_sM
(va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM
(va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM
va_s0))))))))))))))))))))))))))))))))))))))));
va_lemma_norm_mods ([va_Mod_flags; va_Mod_mem_heaplet 6; va_Mod_mem_heaplet 5; va_Mod_mem_heaplet
3; va_Mod_mem_heaplet 2; va_Mod_mem_heaplet 1; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13;
va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7;
va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm
0; va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64
rR11; va_Mod_reg64 rR10; va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRbp; va_Mod_reg64
rRsi; va_Mod_reg64 rRdi; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64
rRax; va_Mod_mem]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g) | {
"file_name": "obj/Vale.AES.X64.GCMdecryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 1334,
"start_col": 0,
"start_line": 1306
} | module Vale.AES.X64.GCMdecryptOpt
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.AES.GCM
open Vale.AES.GHash_s
open Vale.AES.GHash
open Vale.AES.GCM_s
open Vale.AES.X64.AES
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.Poly1305.Math
open Vale.AES.GCM_helpers
open Vale.AES.X64.GHash
open Vale.AES.X64.GCTR
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsStack
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.AES.X64.GF128_Mul
open Vale.X64.Stack
open Vale.X64.CPU_Features_s
open Vale.Math.Poly2.Bits_s
open Vale.AES.X64.AESopt
open Vale.AES.X64.AESGCM
open Vale.AES.X64.AESopt2
open Vale.Lib.Meta
open Vale.AES.X64.GCMencryptOpt
open Vale.AES.OptPublic
open Vale.Lib.Basic
#reset-options "--z3rlimit 20 --max_ifuel 0"
//-- Gcm_extra_bytes
val va_code_Gcm_extra_bytes : alg:algorithm -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_Gcm_extra_bytes alg =
(va_Block (va_CCons (va_code_Load128_buffer (va_op_heaplet_mem_heaplet 5) (va_op_xmm_xmm 0)
(va_op_reg_opr64_reg64 rRax) 0 Secret) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 10)
(va_op_xmm_xmm 0)) (va_CCons (va_code_Ghash_extra_bytes ()) (va_CCons (va_code_Mov128
(va_op_xmm_xmm 0) (va_op_xmm_xmm 11)) (va_CCons (va_code_Pshufb (va_op_xmm_xmm 0)
(va_op_xmm_xmm 9)) (va_CCons (va_code_AESEncryptBlock alg) (va_CCons (va_code_Pxor
(va_op_xmm_xmm 10) (va_op_xmm_xmm 0)) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 5) (va_op_reg_opr64_reg64 rRax) (va_op_xmm_xmm 10) 0 Secret)
(va_CNil ()))))))))))
val va_codegen_success_Gcm_extra_bytes : alg:algorithm -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Gcm_extra_bytes alg =
(va_pbool_and (va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 5) (va_op_xmm_xmm 0)
(va_op_reg_opr64_reg64 rRax) 0 Secret) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm
10) (va_op_xmm_xmm 0)) (va_pbool_and (va_codegen_success_Ghash_extra_bytes ()) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 11)) (va_pbool_and
(va_codegen_success_Pshufb (va_op_xmm_xmm 0) (va_op_xmm_xmm 9)) (va_pbool_and
(va_codegen_success_AESEncryptBlock alg) (va_pbool_and (va_codegen_success_Pxor (va_op_xmm_xmm
10) (va_op_xmm_xmm 0)) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 5) (va_op_reg_opr64_reg64 rRax) (va_op_xmm_xmm 10) 0 Secret)
(va_ttrue ())))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_Gcm_extra_bytes (va_mods:va_mods_t) (alg:algorithm) (inout_b:buffer128) (key:(seq
nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (total_bytes:nat)
(old_hash:quad32) (completed_quads:(seq quad32)) (h_LE:quad32) : (va_quickCode unit
(va_code_Gcm_extra_bytes alg)) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let (len:(va_int_range
1 1)) = 1 in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 188 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 5) (va_op_xmm_xmm 0) (va_op_reg_opr64_reg64
rRax) 0 Secret inout_b 0) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 189 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 10) (va_op_xmm_xmm 0)) (fun (va_s:va_state) _ -> let
(hash_input:quad32) = va_get_xmm 0 va_s in va_QBind va_range1
"***** PRECONDITION NOT MET AT line 193 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Ghash_extra_bytes hkeys_b total_bytes old_hash h_LE completed_quads) (fun
(va_s:va_state) _ -> va_qAssert va_range1
"***** PRECONDITION NOT MET AT line 194 column 5 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(FStar.Seq.Base.equal #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s)
inout_b) (FStar.Seq.Base.create #quad32 1 hash_input)) (let (snap:(FStar.Seq.Base.seq
Vale.X64.Decls.quad32)) = Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s) inout_b in va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 198 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 11)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 199 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Pshufb (va_op_xmm_xmm 0) (va_op_xmm_xmm 9)) (fun (va_s:va_state) _ -> va_QBind
va_range1
"***** PRECONDITION NOT MET AT line 200 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_AESEncryptBlock alg (Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 11 va_s)) key
round_keys keys_b) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 201 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.AES.AES_s.aes_encrypt_LE_reveal ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 204 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Pxor (va_op_xmm_xmm 10) (va_op_xmm_xmm 0)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 205 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 5) (va_op_reg_opr64_reg64 rRax)
(va_op_xmm_xmm 10) 0 Secret inout_b 0) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 207 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.AES.GCTR.gctr_partial_reveal ()) (va_QEmpty (()))))))))))))))
val va_lemma_Gcm_extra_bytes : va_b0:va_code -> va_s0:va_state -> alg:algorithm ->
inout_b:buffer128 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 ->
hkeys_b:buffer128 -> total_bytes:nat -> old_hash:quad32 -> completed_quads:(seq quad32) ->
h_LE:quad32
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Gcm_extra_bytes alg) va_s0 /\ va_get_ok va_s0 /\ (let
(len:(va_int_range 1 1)) = 1 in sse_enabled /\ Vale.X64.Decls.buffers_disjoint128 keys_b
inout_b /\ Vale.X64.Decls.buffers_disjoint128 hkeys_b inout_b /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 5 va_s0) (va_get_reg64 rRax va_s0) inout_b
len (va_get_mem_layout va_s0) Secret /\ len == Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 inout_b /\ va_get_xmm 9 va_s0 == Vale.Def.Words_s.Mkfour
#Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\ aes_reqs alg key round_keys
keys_b (va_get_reg64 rR8 va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\
pclmulqdq_enabled /\ Vale.AES.GHash.hkeys_reqs_priv (Vale.X64.Decls.s128 (va_get_mem_heaplet 0
va_s0) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) /\ Vale.X64.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR9 va_s0 - 32) hkeys_b 8 (va_get_mem_layout va_s0)
Secret /\ va_get_xmm 8 va_s0 == Vale.Def.Types_s.reverse_bytes_quad32
(Vale.AES.GHash.ghash_incremental0 h_LE old_hash completed_quads) /\ FStar.Seq.Base.length
#quad32 completed_quads == total_bytes `op_Division` 16 /\ total_bytes < 16 `op_Multiply`
FStar.Seq.Base.length #quad32 completed_quads + 16 /\ va_get_reg64 rR10 va_s0 == total_bytes
`op_Modulus` 16 /\ total_bytes `op_Modulus` 16 =!= 0 /\ (0 < total_bytes /\ total_bytes < 16
`op_Multiply` Vale.AES.GCM_helpers.bytes_to_quad_size total_bytes) /\ 16 `op_Multiply`
(Vale.AES.GCM_helpers.bytes_to_quad_size total_bytes - 1) < total_bytes)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (len:(va_int_range 1 1)) = 1 in Vale.X64.Decls.modifies_buffer128 inout_b
(va_get_mem_heaplet 5 va_s0) (va_get_mem_heaplet 5 va_sM) /\ Vale.AES.GCTR.gctr_partial alg len
(Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s0) inout_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 5 va_sM) inout_b) key (va_get_xmm 11 va_s0) /\ (let raw_quads =
FStar.Seq.Base.append #quad32 completed_quads (Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s0)
inout_b) in let input_bytes = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let padded_bytes =
Vale.AES.GCTR_s.pad_to_128_bits input_bytes in let input_quads =
Vale.Def.Types_s.le_bytes_to_seq_quad32 padded_bytes in l_and (FStar.Seq.Base.length
#Vale.Def.Types_s.quad32 input_quads > 0) (Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8
va_sM) == Vale.AES.GHash.ghash_incremental h_LE old_hash input_quads))) /\ va_state_eq va_sM
(va_update_flags va_sM (va_update_mem_heaplet 5 va_sM (va_update_xmm 10 va_sM (va_update_xmm 8
va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4
va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0
va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rRcx va_sM (va_update_ok va_sM
(va_update_mem va_sM va_s0))))))))))))))))))
[@"opaque_to_smt"]
let va_lemma_Gcm_extra_bytes va_b0 va_s0 alg inout_b key round_keys keys_b hkeys_b total_bytes
old_hash completed_quads h_LE =
let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_mem_heaplet 5; va_Mod_xmm 10; va_Mod_xmm 8;
va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm
1; va_Mod_xmm 0; va_Mod_reg64 rR11; va_Mod_reg64 rRcx; va_Mod_ok; va_Mod_mem] in
let va_qc = va_qcode_Gcm_extra_bytes va_mods alg inout_b key round_keys keys_b hkeys_b
total_bytes old_hash completed_quads h_LE in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Gcm_extra_bytes alg) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 121 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_get_ok va_sM) /\ (let (len:(va_int_range 1 1)) = 1 in label va_range1
"***** POSTCONDITION NOT MET AT line 174 column 55 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(Vale.X64.Decls.modifies_buffer128 inout_b (va_get_mem_heaplet 5 va_s0) (va_get_mem_heaplet 5
va_sM)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 177 column 95 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(Vale.AES.GCTR.gctr_partial alg len (Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s0) inout_b)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_sM) inout_b) key (va_get_xmm 11 va_s0)) /\ label
va_range1
"***** POSTCONDITION NOT MET AT line 180 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let raw_quads = FStar.Seq.Base.append #quad32 completed_quads (Vale.X64.Decls.s128
(va_get_mem_heaplet 5 va_s0) inout_b) in label va_range1
"***** POSTCONDITION NOT MET AT line 181 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let input_bytes = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes raw_quads) 0 total_bytes in label va_range1
"***** POSTCONDITION NOT MET AT line 182 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let padded_bytes = Vale.AES.GCTR_s.pad_to_128_bits input_bytes in label va_range1
"***** POSTCONDITION NOT MET AT line 183 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let input_quads = Vale.Def.Types_s.le_bytes_to_seq_quad32 padded_bytes in label va_range1
"***** POSTCONDITION NOT MET AT line 186 column 59 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(l_and (FStar.Seq.Base.length #Vale.Def.Types_s.quad32 input_quads > 0)
(Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_sM) == Vale.AES.GHash.ghash_incremental
h_LE old_hash input_quads)))))))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_flags; va_Mod_mem_heaplet 5; va_Mod_xmm 10; va_Mod_xmm 8; va_Mod_xmm
7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_xmm 0; va_Mod_reg64 rR11; va_Mod_reg64 rRcx; va_Mod_ok; va_Mod_mem]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_Gcm_extra_bytes (alg:algorithm) (inout_b:buffer128) (key:(seq nat32)) (round_keys:(seq
quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (total_bytes:nat) (old_hash:quad32)
(completed_quads:(seq quad32)) (h_LE:quad32) (va_s0:va_state) (va_k:(va_state -> unit -> Type0))
: Type0 =
(va_get_ok va_s0 /\ (let (len:(va_int_range 1 1)) = 1 in sse_enabled /\
Vale.X64.Decls.buffers_disjoint128 keys_b inout_b /\ Vale.X64.Decls.buffers_disjoint128 hkeys_b
inout_b /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 5 va_s0) (va_get_reg64 rRax
va_s0) inout_b len (va_get_mem_layout va_s0) Secret /\ len == Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 inout_b /\ va_get_xmm 9 va_s0 == Vale.Def.Words_s.Mkfour
#Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\ aes_reqs alg key round_keys
keys_b (va_get_reg64 rR8 va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\
pclmulqdq_enabled /\ Vale.AES.GHash.hkeys_reqs_priv (Vale.X64.Decls.s128 (va_get_mem_heaplet 0
va_s0) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) /\ Vale.X64.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR9 va_s0 - 32) hkeys_b 8 (va_get_mem_layout va_s0)
Secret /\ va_get_xmm 8 va_s0 == Vale.Def.Types_s.reverse_bytes_quad32
(Vale.AES.GHash.ghash_incremental0 h_LE old_hash completed_quads) /\ FStar.Seq.Base.length
#quad32 completed_quads == total_bytes `op_Division` 16 /\ total_bytes < 16 `op_Multiply`
FStar.Seq.Base.length #quad32 completed_quads + 16 /\ va_get_reg64 rR10 va_s0 == total_bytes
`op_Modulus` 16 /\ total_bytes `op_Modulus` 16 =!= 0 /\ (0 < total_bytes /\ total_bytes < 16
`op_Multiply` Vale.AES.GCM_helpers.bytes_to_quad_size total_bytes) /\ 16 `op_Multiply`
(Vale.AES.GCM_helpers.bytes_to_quad_size total_bytes - 1) < total_bytes) /\ (forall
(va_x_mem:vale_heap) (va_x_rcx:nat64) (va_x_r11:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32)
(va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32)
(va_x_xmm7:quad32) (va_x_xmm8:quad32) (va_x_xmm10:quad32) (va_x_heap5:vale_heap)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_mem_heaplet 5
va_x_heap5 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 8 va_x_xmm8 (va_upd_xmm 7 va_x_xmm7
(va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3
(va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR11
va_x_r11 (va_upd_reg64 rRcx va_x_rcx (va_upd_mem va_x_mem va_s0)))))))))))))) in va_get_ok
va_sM /\ (let (len:(va_int_range 1 1)) = 1 in Vale.X64.Decls.modifies_buffer128 inout_b
(va_get_mem_heaplet 5 va_s0) (va_get_mem_heaplet 5 va_sM) /\ Vale.AES.GCTR.gctr_partial alg len
(Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s0) inout_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 5 va_sM) inout_b) key (va_get_xmm 11 va_s0) /\ (let raw_quads =
FStar.Seq.Base.append #quad32 completed_quads (Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s0)
inout_b) in let input_bytes = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let padded_bytes =
Vale.AES.GCTR_s.pad_to_128_bits input_bytes in let input_quads =
Vale.Def.Types_s.le_bytes_to_seq_quad32 padded_bytes in l_and (FStar.Seq.Base.length
#Vale.Def.Types_s.quad32 input_quads > 0) (Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8
va_sM) == Vale.AES.GHash.ghash_incremental h_LE old_hash input_quads))) ==> va_k va_sM (())))
val va_wpProof_Gcm_extra_bytes : alg:algorithm -> inout_b:buffer128 -> key:(seq nat32) ->
round_keys:(seq quad32) -> keys_b:buffer128 -> hkeys_b:buffer128 -> total_bytes:nat ->
old_hash:quad32 -> completed_quads:(seq quad32) -> h_LE:quad32 -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Gcm_extra_bytes alg inout_b key round_keys keys_b hkeys_b
total_bytes old_hash completed_quads h_LE va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gcm_extra_bytes alg) ([va_Mod_flags;
va_Mod_mem_heaplet 5; va_Mod_xmm 10; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5;
va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR11;
va_Mod_reg64 rRcx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_Gcm_extra_bytes alg inout_b key round_keys keys_b hkeys_b total_bytes old_hash
completed_quads h_LE va_s0 va_k =
let (va_sM, va_f0) = va_lemma_Gcm_extra_bytes (va_code_Gcm_extra_bytes alg) va_s0 alg inout_b key
round_keys keys_b hkeys_b total_bytes old_hash completed_quads h_LE in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_flags va_sM (va_update_mem_heaplet 5 va_sM (va_update_xmm 10
va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5
va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rRcx va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))));
va_lemma_norm_mods ([va_Mod_flags; va_Mod_mem_heaplet 5; va_Mod_xmm 10; va_Mod_xmm 8; va_Mod_xmm
7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_xmm 0; va_Mod_reg64 rR11; va_Mod_reg64 rRcx; va_Mod_mem]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_Gcm_extra_bytes (alg:algorithm) (inout_b:buffer128) (key:(seq nat32)) (round_keys:(seq
quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (total_bytes:nat) (old_hash:quad32)
(completed_quads:(seq quad32)) (h_LE:quad32) : (va_quickCode unit (va_code_Gcm_extra_bytes alg)) =
(va_QProc (va_code_Gcm_extra_bytes alg) ([va_Mod_flags; va_Mod_mem_heaplet 5; va_Mod_xmm 10;
va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm
2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR11; va_Mod_reg64 rRcx; va_Mod_mem])
(va_wp_Gcm_extra_bytes alg inout_b key round_keys keys_b hkeys_b total_bytes old_hash
completed_quads h_LE) (va_wpProof_Gcm_extra_bytes alg inout_b key round_keys keys_b hkeys_b
total_bytes old_hash completed_quads h_LE))
//--
//-- Gcm_blocks128
val va_code_Gcm_blocks128 : alg:algorithm -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_Gcm_blocks128 alg =
(va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rRdi))
(va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRdx)) (va_CCons
(va_code_Mov64 (va_op_dst_opr64_reg64 rRdi) (va_op_opr64_reg64 rRax)) (va_CCons
(va_code_Ghash_buffer ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRdi)
(va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRdx)
(va_op_opr64_reg64 rR12)) (va_CCons (va_code_Gctr_blocks128 alg) (va_CNil ())))))))))
val va_codegen_success_Gcm_blocks128 : alg:algorithm -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Gcm_blocks128 alg =
(va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rRdi))
(va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRdx))
(va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRdi) (va_op_opr64_reg64 rRax))
(va_pbool_and (va_codegen_success_Ghash_buffer ()) (va_pbool_and (va_codegen_success_Mov64
(va_op_dst_opr64_reg64 rRdi) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64
(va_op_dst_opr64_reg64 rRdx) (va_op_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_Gctr_blocks128 alg) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_Gcm_blocks128 (va_mods:va_mods_t) (alg:algorithm) (in_b:buffer128) (out_b:buffer128)
(key:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (h_LE:quad32)
: (va_quickCode unit (va_code_Gcm_blocks128 alg)) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 274 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rRdi)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 275 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRdx)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 276 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rRdi) (va_op_opr64_reg64 rRax)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 277 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Ghash_buffer hkeys_b in_b h_LE (Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8
va_old_s))) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 278 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rRdi) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 279 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rRdx) (va_op_opr64_reg64 rR12)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 280 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Gctr_blocks128 alg in_b out_b key round_keys keys_b) (va_QEmpty (()))))))))))
val va_lemma_Gcm_blocks128 : va_b0:va_code -> va_s0:va_state -> alg:algorithm -> in_b:buffer128 ->
out_b:buffer128 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 ->
hkeys_b:buffer128 -> h_LE:quad32
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Gcm_blocks128 alg) va_s0 /\ va_get_ok va_s0 /\
(sse_enabled /\ Vale.X64.Decls.buffers_disjoint128 keys_b out_b /\
Vale.X64.Decls.buffers_disjoint128 hkeys_b out_b /\ (Vale.X64.Decls.buffers_disjoint128 in_b
out_b \/ in_b == out_b) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0)
(va_get_reg64 rRax va_s0) in_b (va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRdi va_s0) out_b
(va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0) Secret /\ va_get_reg64 rRax va_s0 + 16
`op_Multiply` va_get_reg64 rRdx va_s0 < pow2_64 /\ va_get_reg64 rRdi va_s0 + 16 `op_Multiply`
va_get_reg64 rRdx va_s0 < pow2_64 /\ l_and (Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 in_b == Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out_b)
(Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in_b < pow2_32) /\ va_get_reg64 rRdx
va_s0 == Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in_b /\ va_get_xmm 9 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\
va_get_reg64 rRdx va_s0 < pow2_32 /\ aes_reqs alg key round_keys keys_b (va_get_reg64 rR8
va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ pclmulqdq_enabled /\
Vale.AES.GHash.hkeys_reqs_priv (Vale.X64.Decls.s128 (va_get_mem_heaplet 0 va_s0) hkeys_b)
(Vale.Def.Types_s.reverse_bytes_quad32 h_LE) /\ Vale.X64.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR9 va_s0 - 32) hkeys_b 8 (va_get_mem_layout va_s0)
Secret)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(Vale.X64.Decls.modifies_buffer128 out_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1
va_sM) /\ Vale.AES.GCTR.gctr_partial alg (va_get_reg64 rRdx va_s0) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in_b) (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) out_b) key
(va_get_xmm 11 va_s0) /\ va_get_xmm 11 va_sM == Vale.AES.GCTR.inc32lite (va_get_xmm 11 va_s0)
(va_get_reg64 rRdx va_s0) /\ (va_get_reg64 rRdx va_s0 == 0 ==> l_and (va_get_xmm 8 va_sM ==
va_get_xmm 8 va_s0) (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) out_b ==
Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) out_b)) /\ (va_get_reg64 rRdx va_s0 > 0 ==>
l_and (va_get_reg64 rRdx va_s0 <= FStar.Seq.Base.length #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in_b) ==> FStar.Seq.Base.length
#Vale.X64.Decls.quad32 (FStar.Seq.Base.slice #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in_b) 0 (va_get_reg64 rRdx va_s0)) > 0)
(Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_sM) == Vale.AES.GHash.ghash_incremental
h_LE (Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_s0)) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in_b)))) /\ va_state_eq va_sM (va_update_flags va_sM
(va_update_mem_heaplet 1 va_sM (va_update_xmm 10 va_sM (va_update_xmm 11 va_sM (va_update_xmm 8
va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4
va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0
va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rR10 va_sM
(va_update_reg64 rR11 va_sM (va_update_reg64 rRdi va_sM (va_update_reg64 rRbx va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))))))))))
[@"opaque_to_smt"]
let va_lemma_Gcm_blocks128 va_b0 va_s0 alg in_b out_b key round_keys keys_b hkeys_b h_LE =
let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_mem_heaplet 1; va_Mod_xmm 10; va_Mod_xmm 11;
va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm
2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRdx; va_Mod_reg64 rR10;
va_Mod_reg64 rR11; va_Mod_reg64 rRdi; va_Mod_reg64 rRbx; va_Mod_ok; va_Mod_mem] in
let va_qc = va_qcode_Gcm_blocks128 va_mods alg in_b out_b key round_keys keys_b hkeys_b h_LE in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Gcm_blocks128 alg) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 210 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_get_ok va_sM) /\ (label va_range1
"***** POSTCONDITION NOT MET AT line 255 column 53 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(Vale.X64.Decls.modifies_buffer128 out_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1
va_sM)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 261 column 95 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(Vale.AES.GCTR.gctr_partial alg (va_get_reg64 rRdx va_s0) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in_b) (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) out_b) key
(va_get_xmm 11 va_s0)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 262 column 45 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_get_xmm 11 va_sM == Vale.AES.GCTR.inc32lite (va_get_xmm 11 va_s0) (va_get_reg64 rRdx
va_s0)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 265 column 93 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_get_reg64 rRdx va_s0 == 0 ==> l_and (va_get_xmm 8 va_sM == va_get_xmm 8 va_s0)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) out_b == Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) out_b)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 267 column 131 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_get_reg64 rRdx va_s0 > 0 ==> l_and (va_get_reg64 rRdx va_s0 <= FStar.Seq.Base.length
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in_b) ==>
FStar.Seq.Base.length #Vale.X64.Decls.quad32 (FStar.Seq.Base.slice #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in_b) 0 (va_get_reg64 rRdx va_s0)) > 0)
(Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_sM) == Vale.AES.GHash.ghash_incremental
h_LE (Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_s0)) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in_b))))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_flags; va_Mod_mem_heaplet 1; va_Mod_xmm 10; va_Mod_xmm 11; va_Mod_xmm
8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRdx; va_Mod_reg64 rR10;
va_Mod_reg64 rR11; va_Mod_reg64 rRdi; va_Mod_reg64 rRbx; va_Mod_ok; va_Mod_mem]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_Gcm_blocks128 (alg:algorithm) (in_b:buffer128) (out_b:buffer128) (key:(seq nat32))
(round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (h_LE:quad32) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (sse_enabled /\ Vale.X64.Decls.buffers_disjoint128 keys_b out_b /\
Vale.X64.Decls.buffers_disjoint128 hkeys_b out_b /\ (Vale.X64.Decls.buffers_disjoint128 in_b
out_b \/ in_b == out_b) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0)
(va_get_reg64 rRax va_s0) in_b (va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRdi va_s0) out_b
(va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0) Secret /\ va_get_reg64 rRax va_s0 + 16
`op_Multiply` va_get_reg64 rRdx va_s0 < pow2_64 /\ va_get_reg64 rRdi va_s0 + 16 `op_Multiply`
va_get_reg64 rRdx va_s0 < pow2_64 /\ l_and (Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 in_b == Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out_b)
(Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in_b < pow2_32) /\ va_get_reg64 rRdx
va_s0 == Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in_b /\ va_get_xmm 9 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\
va_get_reg64 rRdx va_s0 < pow2_32 /\ aes_reqs alg key round_keys keys_b (va_get_reg64 rR8
va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ pclmulqdq_enabled /\
Vale.AES.GHash.hkeys_reqs_priv (Vale.X64.Decls.s128 (va_get_mem_heaplet 0 va_s0) hkeys_b)
(Vale.Def.Types_s.reverse_bytes_quad32 h_LE) /\ Vale.X64.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR9 va_s0 - 32) hkeys_b 8 (va_get_mem_layout va_s0)
Secret) /\ (forall (va_x_mem:vale_heap) (va_x_rbx:nat64) (va_x_rdi:nat64) (va_x_r11:nat64)
(va_x_r10:nat64) (va_x_rdx:nat64) (va_x_r12:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32)
(va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32)
(va_x_xmm7:quad32) (va_x_xmm8:quad32) (va_x_xmm11:quad32) (va_x_xmm10:quad32)
(va_x_heap1:vale_heap) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl
(va_upd_mem_heaplet 1 va_x_heap1 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 11 va_x_xmm11
(va_upd_xmm 8 va_x_xmm8 (va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5
(va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rRdx va_x_rdx (va_upd_reg64
rR10 va_x_r10 (va_upd_reg64 rR11 va_x_r11 (va_upd_reg64 rRdi va_x_rdi (va_upd_reg64 rRbx
va_x_rbx (va_upd_mem va_x_mem va_s0))))))))))))))))))) in va_get_ok va_sM /\
(Vale.X64.Decls.modifies_buffer128 out_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1
va_sM) /\ Vale.AES.GCTR.gctr_partial alg (va_get_reg64 rRdx va_s0) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in_b) (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) out_b) key
(va_get_xmm 11 va_s0) /\ va_get_xmm 11 va_sM == Vale.AES.GCTR.inc32lite (va_get_xmm 11 va_s0)
(va_get_reg64 rRdx va_s0) /\ (va_get_reg64 rRdx va_s0 == 0 ==> l_and (va_get_xmm 8 va_sM ==
va_get_xmm 8 va_s0) (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) out_b ==
Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) out_b)) /\ (va_get_reg64 rRdx va_s0 > 0 ==>
l_and (va_get_reg64 rRdx va_s0 <= FStar.Seq.Base.length #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in_b) ==> FStar.Seq.Base.length
#Vale.X64.Decls.quad32 (FStar.Seq.Base.slice #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in_b) 0 (va_get_reg64 rRdx va_s0)) > 0)
(Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_sM) == Vale.AES.GHash.ghash_incremental
h_LE (Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_s0)) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in_b)))) ==> va_k va_sM (())))
val va_wpProof_Gcm_blocks128 : alg:algorithm -> in_b:buffer128 -> out_b:buffer128 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> hkeys_b:buffer128 -> h_LE:quad32 ->
va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Gcm_blocks128 alg in_b out_b key round_keys keys_b hkeys_b
h_LE va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gcm_blocks128 alg) ([va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_xmm 10; va_Mod_xmm 11; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6;
va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0;
va_Mod_reg64 rR12; va_Mod_reg64 rRdx; va_Mod_reg64 rR10; va_Mod_reg64 rR11; va_Mod_reg64 rRdi;
va_Mod_reg64 rRbx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_Gcm_blocks128 alg in_b out_b key round_keys keys_b hkeys_b h_LE va_s0 va_k =
let (va_sM, va_f0) = va_lemma_Gcm_blocks128 (va_code_Gcm_blocks128 alg) va_s0 alg in_b out_b key
round_keys keys_b hkeys_b h_LE in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_flags va_sM (va_update_mem_heaplet 1 va_sM (va_update_xmm 10
va_sM (va_update_xmm 11 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6
va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2
va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR12 va_sM
(va_update_reg64 rRdx va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR11 va_sM
(va_update_reg64 rRdi va_sM (va_update_reg64 rRbx va_sM (va_update_ok va_sM (va_update_mem
va_sM va_s0))))))))))))))))))))));
va_lemma_norm_mods ([va_Mod_flags; va_Mod_mem_heaplet 1; va_Mod_xmm 10; va_Mod_xmm 11; va_Mod_xmm
8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRdx; va_Mod_reg64 rR10;
va_Mod_reg64 rR11; va_Mod_reg64 rRdi; va_Mod_reg64 rRbx; va_Mod_mem]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_Gcm_blocks128 (alg:algorithm) (in_b:buffer128) (out_b:buffer128) (key:(seq nat32))
(round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (h_LE:quad32) : (va_quickCode
unit (va_code_Gcm_blocks128 alg)) =
(va_QProc (va_code_Gcm_blocks128 alg) ([va_Mod_flags; va_Mod_mem_heaplet 1; va_Mod_xmm 10;
va_Mod_xmm 11; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm
3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRdx; va_Mod_reg64
rR10; va_Mod_reg64 rR11; va_Mod_reg64 rRdi; va_Mod_reg64 rRbx; va_Mod_mem])
(va_wp_Gcm_blocks128 alg in_b out_b key round_keys keys_b hkeys_b h_LE)
(va_wpProof_Gcm_blocks128 alg in_b out_b key round_keys keys_b hkeys_b h_LE))
//--
//-- Gcm_blocks
#push-options "--z3rlimit 1000"
val va_code_Gcm_blocks : alg:algorithm -> offset:int -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_Gcm_blocks alg offset =
(va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR13) (va_op_opr64_reg64 rRcx))
(va_CCons (va_code_AddLea64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rR9) (va_const_opr64
32)) (va_CCons (va_code_Load64_stack (va_op_dst_opr64_reg64 rRbx) (va_op_reg_opr64_reg64 rRsp)
(offset + 0)) (va_CCons (va_code_Gcm_blocks_auth ()) (va_CCons (va_code_Load64_stack
(va_op_dst_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rRsp) (offset + 8)) (va_CCons
(va_code_Load64_stack (va_op_dst_opr64_reg64 rRsi) (va_op_reg_opr64_reg64 rRsp) (offset + 16))
(va_CCons (va_code_Load64_stack (va_op_dst_opr64_reg64 rRdx) (va_op_reg_opr64_reg64 rRsp)
(offset + 24)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_op_opr64_reg64 rR13))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 9)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 2) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rR8) 0 Public) (va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 3)
(va_op_reg_opr64_reg64 rRbp) (va_op_xmm_xmm 1) 0 Secret) (va_CCons (va_code_Load_one_lsb
(va_op_xmm_xmm 10)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_xmm_xmm 10)) (va_CCons (va_code_AES_GCM_decrypt_6mult alg) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_xmm_xmm 11) (va_op_reg_opr64_reg64
rRbp) 32 Secret) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR8) (va_op_opr64_reg64 rRcx))
(va_CCons (va_code_Load64_stack (va_op_dst_opr64_reg64 rRax) (va_op_reg_opr64_reg64 rRsp)
(offset + 32)) (va_CCons (va_code_Load64_stack (va_op_dst_opr64_reg64 rRdi)
(va_op_reg_opr64_reg64 rRsp) (offset + 40)) (va_CCons (va_code_Load64_stack
(va_op_dst_opr64_reg64 rRdx) (va_op_reg_opr64_reg64 rRsp) (offset + 48)) (va_CCons
(va_code_Mov64 (va_op_dst_opr64_reg64 rR14) (va_op_opr64_reg64 rRdx)) (va_CCons
(va_code_InitPshufbMask (va_op_xmm_xmm 9) (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_Pshufb (va_op_xmm_xmm 11) (va_op_xmm_xmm 9)) (va_CCons (va_code_Gcm_blocks128 alg)
(va_CCons (va_code_Stack_lemma ()) (va_CCons (va_code_Add64 (va_op_dst_opr64_reg64 rR14)
(va_opr_code_Stack (va_op_reg64_reg64 rRsp) (offset + 24) Public)) (va_CCons (va_code_IMul64
(va_op_dst_opr64_reg64 rR14) (va_const_opr64 16)) (va_CCons (va_code_Load64_stack
(va_op_dst_opr64_reg64 rR13) (va_op_reg_opr64_reg64 rRsp) (offset + 64)) (va_CCons (va_IfElse
(va_cmp_gt (va_op_cmp_reg64 rR13) (va_op_cmp_reg64 rR14)) (va_Block (va_CCons
(va_code_Load64_stack (va_op_dst_opr64_reg64 rRax) (va_op_reg_opr64_reg64 rRsp) (offset + 56))
(va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR10) (va_op_opr64_reg64 rR13)) (va_CCons
(va_code_And64 (va_op_dst_opr64_reg64 rR10) (va_const_opr64 15)) (va_CCons
(va_code_Gcm_extra_bytes alg) (va_CCons (va_Block (va_CNil ())) (va_CNil ()))))))) (va_Block
(va_CNil ()))) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR11) (va_op_opr64_reg64 rR15))
(va_CCons (va_code_Gcm_make_length_quad ()) (va_CCons (va_code_Ghash_register ()) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_xmm_xmm 0) (va_op_reg_opr64_reg64
rRbp) 0 Secret) (va_CCons (va_code_Gctr_register alg) (va_CCons (va_Block (va_CNil ()))
(va_CNil ()))))))))))))))))))))))))))))))))))))
val va_codegen_success_Gcm_blocks : alg:algorithm -> offset:int -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Gcm_blocks alg offset =
(va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR13) (va_op_opr64_reg64 rRcx))
(va_pbool_and (va_codegen_success_AddLea64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rR9)
(va_const_opr64 32)) (va_pbool_and (va_codegen_success_Load64_stack (va_op_dst_opr64_reg64
rRbx) (va_op_reg_opr64_reg64 rRsp) (offset + 0)) (va_pbool_and
(va_codegen_success_Gcm_blocks_auth ()) (va_pbool_and (va_codegen_success_Load64_stack
(va_op_dst_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rRsp) (offset + 8)) (va_pbool_and
(va_codegen_success_Load64_stack (va_op_dst_opr64_reg64 rRsi) (va_op_reg_opr64_reg64 rRsp)
(offset + 16)) (va_pbool_and (va_codegen_success_Load64_stack (va_op_dst_opr64_reg64 rRdx)
(va_op_reg_opr64_reg64 rRsp) (offset + 24)) (va_pbool_and (va_codegen_success_Mov64
(va_op_dst_opr64_reg64 rRcx) (va_op_opr64_reg64 rR13)) (va_pbool_and (va_codegen_success_Mov128
(va_op_xmm_xmm 0) (va_op_xmm_xmm 9)) (va_pbool_and (va_codegen_success_Load128_buffer
(va_op_heaplet_mem_heaplet 2) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64 rR8) 0 Public)
(va_pbool_and (va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 3)
(va_op_reg_opr64_reg64 rRbp) (va_op_xmm_xmm 1) 0 Secret) (va_pbool_and
(va_codegen_success_Load_one_lsb (va_op_xmm_xmm 10)) (va_pbool_and (va_codegen_success_VPaddd
(va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_xmm_xmm 10)) (va_pbool_and
(va_codegen_success_AES_GCM_decrypt_6mult alg) (va_pbool_and (va_codegen_success_Load128_buffer
(va_op_heaplet_mem_heaplet 3) (va_op_xmm_xmm 11) (va_op_reg_opr64_reg64 rRbp) 32 Secret)
(va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR8) (va_op_opr64_reg64 rRcx))
(va_pbool_and (va_codegen_success_Load64_stack (va_op_dst_opr64_reg64 rRax)
(va_op_reg_opr64_reg64 rRsp) (offset + 32)) (va_pbool_and (va_codegen_success_Load64_stack
(va_op_dst_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rRsp) (offset + 40)) (va_pbool_and
(va_codegen_success_Load64_stack (va_op_dst_opr64_reg64 rRdx) (va_op_reg_opr64_reg64 rRsp)
(offset + 48)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR14)
(va_op_opr64_reg64 rRdx)) (va_pbool_and (va_codegen_success_InitPshufbMask (va_op_xmm_xmm 9)
(va_op_reg_opr64_reg64 rR12)) (va_pbool_and (va_codegen_success_Pshufb (va_op_xmm_xmm 11)
(va_op_xmm_xmm 9)) (va_pbool_and (va_codegen_success_Gcm_blocks128 alg) (va_pbool_and
(va_codegen_success_Stack_lemma ()) (va_pbool_and (va_codegen_success_Add64
(va_op_dst_opr64_reg64 rR14) (va_opr_code_Stack (va_op_reg64_reg64 rRsp) (offset + 24) Public))
(va_pbool_and (va_codegen_success_IMul64 (va_op_dst_opr64_reg64 rR14) (va_const_opr64 16))
(va_pbool_and (va_codegen_success_Load64_stack (va_op_dst_opr64_reg64 rR13)
(va_op_reg_opr64_reg64 rRsp) (offset + 64)) (va_pbool_and (va_pbool_and
(va_codegen_success_Load64_stack (va_op_dst_opr64_reg64 rRax) (va_op_reg_opr64_reg64 rRsp)
(offset + 56)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR10)
(va_op_opr64_reg64 rR13)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rR10)
(va_const_opr64 15)) (va_codegen_success_Gcm_extra_bytes alg)))) (va_pbool_and
(va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR11) (va_op_opr64_reg64 rR15)) (va_pbool_and
(va_codegen_success_Gcm_make_length_quad ()) (va_pbool_and (va_codegen_success_Ghash_register
()) (va_pbool_and (va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 3)
(va_op_xmm_xmm 0) (va_op_reg_opr64_reg64 rRbp) 0 Secret) (va_pbool_and
(va_codegen_success_Gctr_register alg) (va_ttrue ()))))))))))))))))))))))))))))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_Gcm_blocks (va_mods:va_mods_t) (alg:algorithm) (offset:int) (auth_b:buffer128)
(abytes_b:buffer128) (in128x6_b:buffer128) (out128x6_b:buffer128) (in128_b:buffer128)
(out128_b:buffer128) (inout_b:buffer128) (iv_b:buffer128) (scratch_b:buffer128) (key:(seq nat32))
(round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) : (va_quickCode unit
(va_code_Gcm_blocks alg offset)) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(abytes_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s +
offset + 0) (va_get_stack va_s) in let (in128x6_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s + offset + 8) (va_get_stack va_s) in let
(out128x6_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s +
offset + 16) (va_get_stack va_s) in let (len128x6:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s + offset + 24) (va_get_stack va_s) in let
(in128_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s +
offset + 32) (va_get_stack va_s) in let (out128_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s + offset + 40) (va_get_stack va_s) in let
(len128:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s + offset
+ 48) (va_get_stack va_s) in let (inout_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s + offset + 56) (va_get_stack va_s) in let
(plain_num_bytes:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s
+ offset + 64) (va_get_stack va_s) in let (h_LE:Vale.Def.Types_s.quad32) =
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 2
(va_get_mem_heaplet 0 va_old_s)) in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 463 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rR13) (va_op_opr64_reg64 rRcx)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 464 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_AddLea64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rR9) (va_const_opr64 32))
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 465 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load64_stack (va_op_dst_opr64_reg64 rRbx) (va_op_reg_opr64_reg64 rRsp) (offset + 0))
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 466 column 5 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Gcm_blocks_auth auth_b abytes_b hkeys_b h_LE) (fun (va_s:va_state)
(auth_quad_seq:(seq quad32)) -> let (y_0:quad32) = Vale.Def.Words_s.Mkfour
#Vale.Def.Types_s.nat32 0 0 0 0 in let (y_auth_bytes:quad32) =
Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_s) in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 473 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load64_stack (va_op_dst_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rRsp) (offset + 8))
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 474 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load64_stack (va_op_dst_opr64_reg64 rRsi) (va_op_reg_opr64_reg64 rRsp) (offset + 16))
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 475 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load64_stack (va_op_dst_opr64_reg64 rRdx) (va_op_reg_opr64_reg64 rRsp) (offset + 24))
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 476 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_op_opr64_reg64 rR13)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 477 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 9)) (fun (va_s:va_state) _ -> let
(iv_BE:Vale.X64.Decls.quad32) = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem_heaplet 2
va_old_s) in let (ctr_BE_1:quad32) = iv_BE in let (ctr_BE_2:quad32) = Vale.AES.GCTR_s.inc32
iv_BE 1 in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 483 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 2) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rR8) 0 Public iv_b 0) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 485 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp)
(va_op_xmm_xmm 1) 0 Secret scratch_b 0) (fun (va_s:va_state) _ -> let (j0:quad32) = va_get_xmm
1 va_s in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 487 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load_one_lsb (va_op_xmm_xmm 10)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 489 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_VPaddd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_xmm_xmm 10)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 491 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_AES_GCM_decrypt_6mult alg h_LE iv_b in128x6_b out128x6_b scratch_b key round_keys
keys_b hkeys_b) (fun (va_s:va_state) _ -> let (y_cipher128x6:Vale.Def.Types_s.quad32) =
Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_s) in let (auth_in:(seq quad32)) =
auth_quad_seq in let (va_arg138:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) =
Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_old_s) in128x6_b in let
(va_arg137:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = auth_in in let
(va_arg136:Vale.Def.Types_s.quad32) = y_auth_bytes in let (va_arg135:Vale.Def.Types_s.quad32) =
y_0 in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 494 column 36 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_ghash_incremental0_append h_LE va_arg135 va_arg136
y_cipher128x6 va_arg137 va_arg138) (let auth_in = FStar.Seq.Base.append #quad32 auth_in
(Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_old_s) in128x6_b) in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 498 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_xmm_xmm 11)
(va_op_reg_opr64_reg64 rRbp) 32 Secret scratch_b 2) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 499 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rR8) (va_op_opr64_reg64 rRcx)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 500 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load64_stack (va_op_dst_opr64_reg64 rRax) (va_op_reg_opr64_reg64 rRsp) (offset + 32))
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 501 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load64_stack (va_op_dst_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rRsp) (offset + 40))
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 502 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load64_stack (va_op_dst_opr64_reg64 rRdx) (va_op_reg_opr64_reg64 rRsp) (offset + 48))
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 503 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rR14) (va_op_opr64_reg64 rRdx)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 504 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_InitPshufbMask (va_op_xmm_xmm 9) (va_op_reg_opr64_reg64 rR12)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 505 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Pshufb (va_op_xmm_xmm 11) (va_op_xmm_xmm 9)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 506 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Gcm_blocks128 alg in128_b out128_b key round_keys keys_b hkeys_b h_LE) (fun
(va_s:va_state) _ -> let (y_cipher128:Vale.Def.Types_s.quad32) =
Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_s) in let (va_arg134:(FStar.Seq.Base.seq
Vale.Def.Types_s.quad32)) = Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_old_s) in128_b in let
(va_arg133:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = auth_in in let
(va_arg132:Vale.Def.Types_s.quad32) = y_0 in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 508 column 36 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_ghash_incremental0_append h_LE va_arg132 y_cipher128x6
y_cipher128 va_arg133 va_arg134) (let auth_in = FStar.Seq.Base.append #quad32 auth_in
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_old_s) in128_b) in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 512 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Stack_lemma (va_op_reg64_reg64 rRsp) (offset + 24) Public) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 512 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Add64 (va_op_dst_opr64_reg64 rR14) (va_opr_code_Stack (va_op_reg64_reg64 rRsp)
(offset + 24) Public)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 513 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_IMul64 (va_op_dst_opr64_reg64 rR14) (va_const_opr64 16)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 514 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load64_stack (va_op_dst_opr64_reg64 rR13) (va_op_reg_opr64_reg64 rRsp) (offset + 64))
(fun (va_s:va_state) _ -> let (y_inout:Vale.Def.Types_s.quad32) = y_cipher128 in let
(plain_byte_seq:(seq quad32)) = empty_seq_quad32 in let (cipher_byte_seq:(seq quad32)) =
empty_seq_quad32 in let (va_arg131:Vale.Def.Types_s.quad32) = va_get_xmm 11 va_s in let
(va_arg130:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = key in let
(va_arg129:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = cipher_byte_seq in let
(va_arg128:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = plain_byte_seq in let
(va_arg127:Vale.AES.AES_common_s.algorithm) = alg in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 519 column 29 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.AES.GCTR.gctr_partial_opaque_init va_arg127 va_arg128 va_arg129 va_arg130
va_arg131) (let (total_bytes:(va_int_at_least 0)) = FStar.Seq.Base.length #quad32 auth_quad_seq
`op_Multiply` 16 + plain_num_bytes in va_QBind va_range1
"***** PRECONDITION NOT MET AT line 523 column 8 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_qIf va_mods (Cmp_gt (va_op_cmp_reg64 rR13) (va_op_cmp_reg64 rR14)) (qblock va_mods (fun
(va_s:va_state) -> va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 525 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load64_stack (va_op_dst_opr64_reg64 rRax) (va_op_reg_opr64_reg64 rRsp) (offset + 56))
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 526 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rR10) (va_op_opr64_reg64 rR13)) (fun (va_s:va_state) _
-> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 527 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.Poly1305.Math.lemma_poly_bits64 ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 528 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_And64 (va_op_dst_opr64_reg64 rR10) (va_const_opr64 15)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 532 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Gcm_extra_bytes alg inout_b key round_keys keys_b hkeys_b total_bytes y_0 auth_in
h_LE) (fun (va_s:va_state) _ -> let y_inout = Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm
8 va_s) in let (raw_auth_quads:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.append #quad32
auth_in (Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_old_s) inout_b) in va_qAssertSquash
va_range1
"***** EXPRESSION PRECONDITIONS NOT MET WITHIN line 536 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
((fun a_1906 (s_1907:(FStar.Seq.Base.seq a_1906)) (i_1908:Prims.nat) (j_1909:Prims.nat) -> let
(j_1869:Prims.nat) = j_1909 in Prims.b2t (Prims.op_AmpAmp (Prims.op_LessThanOrEqual i_1908
j_1869) (Prims.op_LessThanOrEqual j_1869 (FStar.Seq.Base.length #a_1906 s_1907))))
Vale.Def.Types_s.nat8 (Vale.Def.Types_s.le_seq_quad32_to_bytes raw_auth_quads) 0 total_bytes)
(fun _ -> let (auth_input_bytes:(FStar.Seq.Base.seq Vale.Def.Types_s.nat8)) =
FStar.Seq.Base.slice #Vale.Def.Types_s.nat8 (Vale.Def.Types_s.le_seq_quad32_to_bytes
raw_auth_quads) 0 total_bytes in let (padded_auth_bytes:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat8)) = Vale.AES.GCTR_s.pad_to_128_bits auth_input_bytes in let auth_in =
Vale.Def.Types_s.le_bytes_to_seq_quad32 padded_auth_bytes in let plain_byte_seq =
Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_old_s) inout_b in let cipher_byte_seq =
Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s) inout_b in va_QEmpty ((auth_in,
cipher_byte_seq, plain_byte_seq, y_inout)))))))))) (qblock va_mods (fun (va_s:va_state) ->
va_QEmpty ((auth_in, cipher_byte_seq, plain_byte_seq, y_inout))))) (fun (va_s:va_state) va_g ->
let ((auth_in:(seq quad32)), (cipher_byte_seq:(seq quad32)), (plain_byte_seq:(seq quad32)),
(y_inout:Vale.Def.Types_s.quad32)) = va_g in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 547 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rR11) (va_op_opr64_reg64 rR15)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 548 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Gcm_make_length_quad ()) (fun (va_s:va_state) _ -> let
(length_quad32:Vale.Def.Types_s.quad32) = Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 0
va_s) in va_QBind va_range1
"***** PRECONDITION NOT MET AT line 551 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Ghash_register hkeys_b h_LE y_inout) (fun (va_s:va_state) _ -> let
(y_final:Vale.Def.Types_s.quad32) = Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_s)
in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 554 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_xmm_xmm 0) (va_op_reg_opr64_reg64
rRbp) 0 Secret scratch_b 0) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 557 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_quick_Gctr_register alg key round_keys keys_b) (fun (va_s:va_state) _ -> let
(va_arg126:Vale.Def.Types_s.quad32) = va_get_xmm 8 va_s in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 560 column 40 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.Arch.Types.le_seq_quad32_to_bytes_of_singleton va_arg126)
(va_qAssertSquash va_range1
"***** EXPRESSION PRECONDITIONS NOT MET WITHIN line 561 column 5 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
((fun (icb_BE_677:Vale.Def.Types_s.quad32) (plain_LE_678:Vale.Def.Types_s.quad32)
(alg_679:Vale.AES.AES_common_s.algorithm) (key_680:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32))
(i_681:Prims.int) -> Vale.AES.AES_s.is_aes_key_LE alg_679 key_680) j0 y_final alg key 0) (fun _
-> va_qAssert va_range1
"***** PRECONDITION NOT MET AT line 561 column 5 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_get_xmm 8 va_s == Vale.AES.GCTR_s.gctr_encrypt_block j0 y_final alg key 0) (let
(plain128:(FStar.Seq.Base.seq Vale.X64.Decls.quad32)) = FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_old_s) in128x6_b)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_old_s) in128_b) in let
(cipher128:(FStar.Seq.Base.seq Vale.X64.Decls.quad32)) = FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s) in128x6_b)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s) in128_b) in va_qAssert va_range1
"***** PRECONDITION NOT MET AT line 566 column 5 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(FStar.Seq.Base.length #quad32 plain_byte_seq == 0 ==> FStar.Seq.Base.equal
#Vale.X64.Decls.quad32 (FStar.Seq.Base.append #Vale.X64.Decls.quad32 plain128 plain_byte_seq)
plain128) (va_qAssert va_range1
"***** PRECONDITION NOT MET AT line 567 column 5 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(FStar.Seq.Base.length #quad32 cipher_byte_seq == 0 ==> FStar.Seq.Base.equal
#Vale.X64.Decls.quad32 (FStar.Seq.Base.append #Vale.X64.Decls.quad32 cipher128 cipher_byte_seq)
cipher128) (let (va_arg125:Vale.Def.Types_s.quad32) = Vale.AES.GCTR.inc32lite ctr_BE_2 len128x6
in let (va_arg124:Vale.Def.Types_s.quad32) = ctr_BE_2 in let (va_arg123:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = key in let (va_arg122:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32))
= Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s) out128_b in let
(va_arg121:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_old_s) in128_b in let (va_arg120:(FStar.Seq.Base.seq
Vale.Def.Types_s.quad32)) = Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s) out128x6_b in let
(va_arg119:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = Vale.X64.Decls.s128
(va_get_mem_heaplet 6 va_old_s) in128x6_b in let (va_arg118:Prims.nat) = len128 in let
(va_arg117:Prims.nat) = len128x6 in let (va_arg116:Vale.AES.AES_common_s.algorithm) = alg in
va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 569 column 30 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.AES.GCTR.lemma_gctr_partial_append va_arg116 va_arg117 va_arg118
va_arg119 va_arg120 va_arg121 va_arg122 va_arg123 va_arg124 va_arg125) (let
(va_arg115:Vale.Def.Types_s.quad32) = Vale.AES.GCTR.inc32lite (Vale.AES.GCTR.inc32lite ctr_BE_2
len128x6) len128 in let (va_arg114:Vale.Def.Types_s.quad32) = ctr_BE_2 in let
(va_arg113:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = key in let
(va_arg112:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = cipher_byte_seq in let
(va_arg111:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = plain_byte_seq in let
(va_arg110:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s) out128x6_b)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s) out128_b) in let
(va_arg109:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_old_s) in128x6_b)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_old_s) in128_b) in let (va_arg108:Prims.nat) =
FStar.Seq.Base.length #quad32 plain_byte_seq in let (va_arg107:Prims.nat) = len128x6 + len128
in let (va_arg106:Vale.AES.AES_common_s.algorithm) = alg in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 575 column 30 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.AES.GCTR.lemma_gctr_partial_append va_arg106 va_arg107 va_arg108
va_arg109 va_arg110 va_arg111 va_arg112 va_arg113 va_arg114 va_arg115) (let
(va_arg105:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = auth_in in let
(va_arg104:Vale.Def.Types_s.quad32) = y_0 in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 583 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_hash_append2 h_LE va_arg104 y_inout y_final va_arg105
length_quad32) (let auth_in = FStar.Seq.Base.append #quad32 auth_in (FStar.Seq.Base.create
#Vale.Def.Types_s.quad32 1 length_quad32) in let (va_arg103:(FStar.Seq.Base.seq
Vale.Def.Types_s.quad32)) = auth_in in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 585 column 31 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.ghash_incremental_to_ghash h_LE va_arg103) (va_QEmpty
(()))))))))))))))))))))))))))))))))))))))))))))))))
val va_lemma_Gcm_blocks : va_b0:va_code -> va_s0:va_state -> alg:algorithm -> offset:int ->
auth_b:buffer128 -> abytes_b:buffer128 -> in128x6_b:buffer128 -> out128x6_b:buffer128 ->
in128_b:buffer128 -> out128_b:buffer128 -> inout_b:buffer128 -> iv_b:buffer128 ->
scratch_b:buffer128 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 ->
hkeys_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Gcm_blocks alg offset) va_s0 /\ va_get_ok va_s0 /\
(let (abytes_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + offset + 0) (va_get_stack va_s0) in let (in128x6_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 8) (va_get_stack va_s0) in
let (out128x6_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + offset + 16) (va_get_stack va_s0) in let (len128x6:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 24) (va_get_stack va_s0) in
let (in128_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0
+ offset + 32) (va_get_stack va_s0) in let (out128_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 40) (va_get_stack va_s0) in
let (len128:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
offset + 48) (va_get_stack va_s0) in let (inout_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 56) (va_get_stack va_s0) in
let (plain_num_bytes:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + offset + 64) (va_get_stack va_s0) in let (h_LE:Vale.Def.Types_s.quad32) =
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 2
(va_get_mem_heaplet 0 va_s0)) in sse_enabled /\ movbe_enabled /\
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + offset + 0) (va_get_stack va_s0)
Public (va_get_stackTaint va_s0) /\ Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp
va_s0 + offset + 8) (va_get_stack va_s0) Public (va_get_stackTaint va_s0) /\
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + offset + 16) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0) /\ Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64
rRsp va_s0 + offset + 24) (va_get_stack va_s0) Public (va_get_stackTaint va_s0) /\
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + offset + 32) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0) /\ Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64
rRsp va_s0 + offset + 40) (va_get_stack va_s0) Public (va_get_stackTaint va_s0) /\
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + offset + 48) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0) /\ Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64
rRsp va_s0 + offset + 56) (va_get_stack va_s0) Public (va_get_stackTaint va_s0) /\
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + offset + 64) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet
1 va_s0) (va_get_reg64 rRdi va_s0) auth_b (va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 7 va_s0) abytes_ptr abytes_b 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 2
va_s0) (va_get_reg64 rR8 va_s0) iv_b 1 (va_get_mem_layout va_s0) Public /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 6 va_s0) in128x6_ptr in128x6_b len128x6
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 6
va_s0) out128x6_ptr out128x6_b len128x6 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0) in128_ptr in128_b len128
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) out128_ptr out128_b len128 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 5 va_s0) inout_ptr inout_b 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 3
va_s0) (va_get_reg64 rRbp va_s0) scratch_b 9 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR9 va_s0) hkeys_b 8
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.buffer_disjoints128 iv_b ([keys_b;
scratch_b; in128x6_b; out128x6_b; hkeys_b; in128_b; out128_b; inout_b]) /\
Vale.X64.Decls.buffer_disjoints128 scratch_b ([keys_b; in128x6_b; out128x6_b; in128_b;
out128_b; inout_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128x6_b ([keys_b;
hkeys_b; in128_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128_b ([keys_b; hkeys_b;
out128x6_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 inout_b ([keys_b; hkeys_b;
out128x6_b; out128_b]) /\ (Vale.X64.Decls.buffers_disjoint128 in128x6_b out128x6_b \/ in128x6_b
== out128x6_b) /\ (Vale.X64.Decls.buffers_disjoint128 in128_b out128_b \/ in128_b == out128_b)
/\ va_get_reg64 rRdi va_s0 + 16 `op_Multiply` va_get_reg64 rRdx va_s0 < pow2_64 /\ in128x6_ptr
+ 16 `op_Multiply` len128x6 < pow2_64 /\ out128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\
in128_ptr + 16 `op_Multiply` len128 < pow2_64 /\ out128_ptr + 16 `op_Multiply` len128 < pow2_64
/\ inout_ptr + 16 < pow2_64 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 auth_b ==
va_get_reg64 rRdx va_s0 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 abytes_b == 1
/\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b ==
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128x6_b /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b == Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 out128_b /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128
in128x6_b == len128x6 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b ==
len128 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 inout_b == 1 /\
plain_num_bytes < pow2_32 /\ va_get_reg64 rRsi va_s0 < pow2_32 /\ va_get_reg64 rR9 va_s0 + 32 <
pow2_64 /\ Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_b (va_get_mem_heaplet 0
va_s0) + 128 < pow2_64 /\ len128x6 `op_Modulus` 6 == 0 /\ (len128x6 > 0 ==> len128x6 >= 6) /\
12 + len128x6 + 6 < pow2_32 /\ (va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128
(128 `op_Division` 8) <= plain_num_bytes /\ plain_num_bytes < va_mul_nat len128x6 (128
`op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8) + 128 `op_Division` 8) /\
(va_mul_nat (va_get_reg64 rRdx va_s0) (128 `op_Division` 8) <= va_get_reg64 rRsi va_s0 /\
va_get_reg64 rRsi va_s0 < va_mul_nat (va_get_reg64 rRdx va_s0) (128 `op_Division` 8) + 128
`op_Division` 8) /\ aes_reqs alg key round_keys keys_b (va_get_reg64 rRcx va_s0)
(va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ pclmulqdq_enabled /\
Vale.AES.GHash.hkeys_reqs_priv (Vale.X64.Decls.s128 (va_get_mem_heaplet 0 va_s0) hkeys_b)
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key
(Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (abytes_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + offset + 0) (va_get_stack va_s0) in let (in128x6_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 8) (va_get_stack va_s0) in
let (out128x6_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + offset + 16) (va_get_stack va_s0) in let (len128x6:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 24) (va_get_stack va_s0) in
let (in128_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0
+ offset + 32) (va_get_stack va_s0) in let (out128_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 40) (va_get_stack va_s0) in
let (len128:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
offset + 48) (va_get_stack va_s0) in let (inout_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 56) (va_get_stack va_s0) in
let (plain_num_bytes:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + offset + 64) (va_get_stack va_s0) in let (h_LE:Vale.Def.Types_s.quad32) =
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 2
(va_get_mem_heaplet 0 va_s0)) in Vale.X64.Decls.modifies_buffer128 out128_b (va_get_mem_heaplet
1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ Vale.X64.Decls.modifies_buffer128 iv_b
(va_get_mem_heaplet 2 va_s0) (va_get_mem_heaplet 2 va_sM) /\ Vale.X64.Decls.modifies_buffer128
scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) /\
Vale.X64.Decls.modifies_buffer128 inout_b (va_get_mem_heaplet 5 va_s0) (va_get_mem_heaplet 5
va_sM) /\ Vale.X64.Decls.modifies_buffer128 out128x6_b (va_get_mem_heaplet 6 va_s0)
(va_get_mem_heaplet 6 va_sM) /\ plain_num_bytes < pow2_32 /\ va_get_reg64 rRsi va_s0 < pow2_32
/\ (let iv_BE = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem_heaplet 2 va_s0) in let
(ctr_BE_1:quad32) = iv_BE in let (ctr_BE_2:quad32) = Vale.AES.GCTR_s.inc32 iv_BE 1 in let
(plain_in:(seq quad32)) = (if (plain_num_bytes > (len128x6 + len128) `op_Multiply` 128
`op_Division` 8) then FStar.Seq.Base.append #Vale.X64.Decls.quad32 (FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s0) in128x6_b)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in128_b)) (Vale.X64.Decls.s128
(va_get_mem_heaplet 5 va_s0) inout_b) else FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s0) in128x6_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in128_b)) in let (cipher_out:(seq quad32)) = (if (plain_num_bytes
> (len128x6 + len128) `op_Multiply` 128 `op_Division` 8) then FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (FStar.Seq.Base.append #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128
(va_get_mem_heaplet 6 va_sM) out128x6_b) (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM)
out128_b)) (Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_sM) inout_b) else
FStar.Seq.Base.append #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_sM)
out128x6_b) (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) out128_b)) in let
(cipher_bound:nat) = (if (plain_num_bytes > (len128x6 + len128) `op_Multiply` 128 `op_Division`
8) then (len128x6 + len128 + 1) else (len128x6 + len128)) in Vale.AES.GCTR.gctr_partial alg
cipher_bound plain_in cipher_out key ctr_BE_2 /\ (let (length_quad:quad32) =
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.Def.Types_s.insert_nat64
(Vale.Def.Types_s.insert_nat64 (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0) (8
`op_Multiply` va_get_reg64 rRsi va_s0) 1) (8 `op_Multiply` plain_num_bytes) 0) in let
(raw_auth_quads:(seq quad32)) = (if (va_get_reg64 rRsi va_s0 > va_get_reg64 rRdx va_s0
`op_Multiply` 128 `op_Division` 8) then FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) auth_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 7 va_s0) abytes_b) else Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0)
auth_b) in let (auth_input_bytes:(seq nat8)) = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes raw_auth_quads) 0 (va_get_reg64 rRsi va_s0) in let
(padded_auth_bytes:(seq nat8)) = Vale.AES.GCTR_s.pad_to_128_bits auth_input_bytes in let
(auth_quad_seq:(seq quad32)) = Vale.Def.Types_s.le_bytes_to_seq_quad32 padded_auth_bytes in let
(raw_quad_seq:(seq quad32)) = FStar.Seq.Base.append #quad32 (FStar.Seq.Base.append #quad32
auth_quad_seq (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s0) in128x6_b))
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in128_b) in let (total_bytes:nat) =
FStar.Seq.Base.length #quad32 auth_quad_seq `op_Multiply` 16 + plain_num_bytes in let
(raw_quad_seq:(seq quad32)) = (if (plain_num_bytes > (len128x6 + len128) `op_Multiply` 128
`op_Division` 8) then (let (ab:(seq nat8)) = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes (FStar.Seq.Base.append #quad32 raw_quad_seq
(Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s0) inout_b))) 0 total_bytes in let (pb:(seq
nat8)) = Vale.AES.GCTR_s.pad_to_128_bits ab in Vale.Def.Types_s.le_bytes_to_seq_quad32 pb) else
raw_quad_seq) in let (auth_quad_seq:(seq quad32)) = FStar.Seq.Base.append #quad32 raw_quad_seq
(FStar.Seq.Base.create #quad32 1 length_quad) in va_get_xmm 8 va_sM ==
Vale.AES.GCTR_s.gctr_encrypt_block ctr_BE_1 (Vale.AES.GHash_s.ghash_LE h_LE auth_quad_seq) alg
key 0))) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_mem_heaplet 6 va_sM
(va_update_mem_heaplet 5 va_sM (va_update_mem_heaplet 3 va_sM (va_update_mem_heaplet 2 va_sM
(va_update_mem_heaplet 1 va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm
13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm
9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5
va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM
(va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM
(va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM
(va_update_reg64 rRbp va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdi va_sM
(va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM
(va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM
va_s0)))))))))))))))))))))))))))))))))))))))))
[@"opaque_to_smt"]
let va_lemma_Gcm_blocks va_b0 va_s0 alg offset auth_b abytes_b in128x6_b out128x6_b in128_b
out128_b inout_b iv_b scratch_b key round_keys keys_b hkeys_b =
let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_mem_heaplet 6; va_Mod_mem_heaplet 5;
va_Mod_mem_heaplet 3; va_Mod_mem_heaplet 2; va_Mod_mem_heaplet 1; va_Mod_xmm 15; va_Mod_xmm 14;
va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8;
va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm
1; va_Mod_xmm 0; va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12;
va_Mod_reg64 rR11; va_Mod_reg64 rR10; va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRbp;
va_Mod_reg64 rRsi; va_Mod_reg64 rRdi; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx;
va_Mod_reg64 rRax; va_Mod_ok; va_Mod_mem] in
let va_qc = va_qcode_Gcm_blocks va_mods alg offset auth_b abytes_b in128x6_b out128x6_b in128_b
out128_b inout_b iv_b scratch_b key round_keys keys_b hkeys_b in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Gcm_blocks alg offset) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 283 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_get_ok va_sM) /\ (let (abytes_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + offset + 0) (va_get_stack va_s0) in let
(in128x6_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
offset + 8) (va_get_stack va_s0) in let (out128x6_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 16) (va_get_stack va_s0) in
let (len128x6:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
offset + 24) (va_get_stack va_s0) in let (in128_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 32) (va_get_stack va_s0) in
let (out128_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0
+ offset + 40) (va_get_stack va_s0) in let (len128:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 48) (va_get_stack va_s0) in
let (inout_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0
+ offset + 56) (va_get_stack va_s0) in let (plain_num_bytes:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 64) (va_get_stack va_s0) in
let (h_LE:Vale.Def.Types_s.quad32) = Vale.Def.Types_s.reverse_bytes_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 0 va_s0)) in label va_range1
"***** POSTCONDITION NOT MET AT line 396 column 56 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(Vale.X64.Decls.modifies_buffer128 out128_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1
va_sM)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 397 column 52 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(Vale.X64.Decls.modifies_buffer128 iv_b (va_get_mem_heaplet 2 va_s0) (va_get_mem_heaplet 2
va_sM)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 398 column 57 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(Vale.X64.Decls.modifies_buffer128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3
va_sM)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 399 column 55 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(Vale.X64.Decls.modifies_buffer128 inout_b (va_get_mem_heaplet 5 va_s0) (va_get_mem_heaplet 5
va_sM)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 400 column 58 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(Vale.X64.Decls.modifies_buffer128 out128x6_b (va_get_mem_heaplet 6 va_s0) (va_get_mem_heaplet
6 va_sM)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 403 column 39 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(plain_num_bytes < pow2_32) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 404 column 38 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_get_reg64 rRsi va_s0 < pow2_32) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 406 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let iv_BE = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem_heaplet 2 va_s0) in label
va_range1
"***** POSTCONDITION NOT MET AT line 408 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (ctr_BE_1:quad32) = iv_BE in label va_range1
"***** POSTCONDITION NOT MET AT line 409 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (ctr_BE_2:quad32) = Vale.AES.GCTR_s.inc32 iv_BE 1 in label va_range1
"***** POSTCONDITION NOT MET AT line 412 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (plain_in:(seq quad32)) = va_if (plain_num_bytes > (len128x6 + len128) `op_Multiply` 128
`op_Division` 8) (fun _ -> FStar.Seq.Base.append #Vale.X64.Decls.quad32 (FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s0) in128x6_b)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in128_b)) (Vale.X64.Decls.s128
(va_get_mem_heaplet 5 va_s0) inout_b)) (fun _ -> FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s0) in128x6_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in128_b)) in label va_range1
"***** POSTCONDITION NOT MET AT line 421 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (cipher_out:(seq quad32)) = va_if (plain_num_bytes > (len128x6 + len128) `op_Multiply` 128
`op_Division` 8) (fun _ -> FStar.Seq.Base.append #Vale.X64.Decls.quad32 (FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_sM) out128x6_b)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) out128_b)) (Vale.X64.Decls.s128
(va_get_mem_heaplet 5 va_sM) inout_b)) (fun _ -> FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_sM) out128x6_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_sM) out128_b)) in label va_range1
"***** POSTCONDITION NOT MET AT line 430 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (cipher_bound:nat) = va_if (plain_num_bytes > (len128x6 + len128) `op_Multiply` 128
`op_Division` 8) (fun _ -> len128x6 + len128 + 1) (fun _ -> len128x6 + len128) in label
va_range1
"***** POSTCONDITION NOT MET AT line 434 column 77 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(Vale.AES.GCTR.gctr_partial alg cipher_bound plain_in cipher_out key ctr_BE_2) /\ label
va_range1
"***** POSTCONDITION NOT MET AT line 438 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (length_quad:quad32) = Vale.Def.Types_s.reverse_bytes_quad32
(Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Words_s.Mkfour
#Vale.Def.Types_s.nat32 0 0 0 0) (8 `op_Multiply` va_get_reg64 rRsi va_s0) 1) (8 `op_Multiply`
plain_num_bytes) 0) in label va_range1
"***** POSTCONDITION NOT MET AT line 440 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (raw_auth_quads:(seq quad32)) = va_if (va_get_reg64 rRsi va_s0 > va_get_reg64 rRdx va_s0
`op_Multiply` 128 `op_Division` 8) (fun _ -> FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) auth_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 7 va_s0) abytes_b)) (fun _ -> Vale.X64.Decls.s128 (va_get_mem_heaplet 1
va_s0) auth_b) in label va_range1
"***** POSTCONDITION NOT MET AT line 444 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (auth_input_bytes:(seq nat8)) = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes raw_auth_quads) 0 (va_get_reg64 rRsi va_s0) in label
va_range1
"***** POSTCONDITION NOT MET AT line 445 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (padded_auth_bytes:(seq nat8)) = Vale.AES.GCTR_s.pad_to_128_bits auth_input_bytes in label
va_range1
"***** POSTCONDITION NOT MET AT line 446 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (auth_quad_seq:(seq quad32)) = Vale.Def.Types_s.le_bytes_to_seq_quad32 padded_auth_bytes
in label va_range1
"***** POSTCONDITION NOT MET AT line 448 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (raw_quad_seq:(seq quad32)) = FStar.Seq.Base.append #quad32 (FStar.Seq.Base.append #quad32
auth_quad_seq (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s0) in128x6_b))
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in128_b) in label va_range1
"***** POSTCONDITION NOT MET AT line 452 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (total_bytes:nat) = FStar.Seq.Base.length #quad32 auth_quad_seq `op_Multiply` 16 +
plain_num_bytes in label va_range1
"***** POSTCONDITION NOT MET AT line 453 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (raw_quad_seq:(seq quad32)) = va_if (plain_num_bytes > (len128x6 + len128) `op_Multiply`
128 `op_Division` 8) (fun _ -> let (ab:(seq nat8)) = FStar.Seq.Base.slice
#Vale.Def.Types_s.nat8 (Vale.Def.Types_s.le_seq_quad32_to_bytes (FStar.Seq.Base.append #quad32
raw_quad_seq (Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s0) inout_b))) 0 total_bytes in let
(pb:(seq nat8)) = Vale.AES.GCTR_s.pad_to_128_bits ab in Vale.Def.Types_s.le_bytes_to_seq_quad32
pb) (fun _ -> raw_quad_seq) in label va_range1
"***** POSTCONDITION NOT MET AT line 460 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(let (auth_quad_seq:(seq quad32)) = FStar.Seq.Base.append #quad32 raw_quad_seq
(FStar.Seq.Base.create #quad32 1 length_quad) in label va_range1
"***** POSTCONDITION NOT MET AT line 461 column 106 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GCMdecryptOpt.vaf *****"
(va_get_xmm 8 va_sM == Vale.AES.GCTR_s.gctr_encrypt_block ctr_BE_1 (Vale.AES.GHash_s.ghash_LE
h_LE auth_quad_seq) alg key 0)))))))))))))))))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_flags; va_Mod_mem_heaplet 6; va_Mod_mem_heaplet 5; va_Mod_mem_heaplet
3; va_Mod_mem_heaplet 2; va_Mod_mem_heaplet 1; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13;
va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7;
va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm
0; va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64
rR11; va_Mod_reg64 rR10; va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRbp; va_Mod_reg64
rRsi; va_Mod_reg64 rRdi; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64
rRax; va_Mod_ok; va_Mod_mem]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_Gcm_blocks (alg:algorithm) (offset:int) (auth_b:buffer128) (abytes_b:buffer128)
(in128x6_b:buffer128) (out128x6_b:buffer128) (in128_b:buffer128) (out128_b:buffer128)
(inout_b:buffer128) (iv_b:buffer128) (scratch_b:buffer128) (key:(seq nat32)) (round_keys:(seq
quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit ->
Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (abytes_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + offset + 0) (va_get_stack va_s0) in let
(in128x6_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
offset + 8) (va_get_stack va_s0) in let (out128x6_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 16) (va_get_stack va_s0) in
let (len128x6:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
offset + 24) (va_get_stack va_s0) in let (in128_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 32) (va_get_stack va_s0) in
let (out128_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0
+ offset + 40) (va_get_stack va_s0) in let (len128:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 48) (va_get_stack va_s0) in
let (inout_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0
+ offset + 56) (va_get_stack va_s0) in let (plain_num_bytes:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 64) (va_get_stack va_s0) in
let (h_LE:Vale.Def.Types_s.quad32) = Vale.Def.Types_s.reverse_bytes_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 0 va_s0)) in sse_enabled /\
movbe_enabled /\ Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + offset + 0)
(va_get_stack va_s0) Public (va_get_stackTaint va_s0) /\ Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + offset + 8) (va_get_stack va_s0) Public (va_get_stackTaint va_s0) /\
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + offset + 16) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0) /\ Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64
rRsp va_s0 + offset + 24) (va_get_stack va_s0) Public (va_get_stackTaint va_s0) /\
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + offset + 32) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0) /\ Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64
rRsp va_s0 + offset + 40) (va_get_stack va_s0) Public (va_get_stackTaint va_s0) /\
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + offset + 48) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0) /\ Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64
rRsp va_s0 + offset + 56) (va_get_stack va_s0) Public (va_get_stackTaint va_s0) /\
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + offset + 64) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet
1 va_s0) (va_get_reg64 rRdi va_s0) auth_b (va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 7 va_s0) abytes_ptr abytes_b 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 2
va_s0) (va_get_reg64 rR8 va_s0) iv_b 1 (va_get_mem_layout va_s0) Public /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 6 va_s0) in128x6_ptr in128x6_b len128x6
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 6
va_s0) out128x6_ptr out128x6_b len128x6 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0) in128_ptr in128_b len128
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) out128_ptr out128_b len128 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 5 va_s0) inout_ptr inout_b 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 3
va_s0) (va_get_reg64 rRbp va_s0) scratch_b 9 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR9 va_s0) hkeys_b 8
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.buffer_disjoints128 iv_b ([keys_b;
scratch_b; in128x6_b; out128x6_b; hkeys_b; in128_b; out128_b; inout_b]) /\
Vale.X64.Decls.buffer_disjoints128 scratch_b ([keys_b; in128x6_b; out128x6_b; in128_b;
out128_b; inout_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128x6_b ([keys_b;
hkeys_b; in128_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128_b ([keys_b; hkeys_b;
out128x6_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 inout_b ([keys_b; hkeys_b;
out128x6_b; out128_b]) /\ (Vale.X64.Decls.buffers_disjoint128 in128x6_b out128x6_b \/ in128x6_b
== out128x6_b) /\ (Vale.X64.Decls.buffers_disjoint128 in128_b out128_b \/ in128_b == out128_b)
/\ va_get_reg64 rRdi va_s0 + 16 `op_Multiply` va_get_reg64 rRdx va_s0 < pow2_64 /\ in128x6_ptr
+ 16 `op_Multiply` len128x6 < pow2_64 /\ out128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\
in128_ptr + 16 `op_Multiply` len128 < pow2_64 /\ out128_ptr + 16 `op_Multiply` len128 < pow2_64
/\ inout_ptr + 16 < pow2_64 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 auth_b ==
va_get_reg64 rRdx va_s0 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 abytes_b == 1
/\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b ==
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128x6_b /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b == Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 out128_b /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128
in128x6_b == len128x6 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b ==
len128 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 inout_b == 1 /\
plain_num_bytes < pow2_32 /\ va_get_reg64 rRsi va_s0 < pow2_32 /\ va_get_reg64 rR9 va_s0 + 32 <
pow2_64 /\ Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_b (va_get_mem_heaplet 0
va_s0) + 128 < pow2_64 /\ len128x6 `op_Modulus` 6 == 0 /\ (len128x6 > 0 ==> len128x6 >= 6) /\
12 + len128x6 + 6 < pow2_32 /\ (va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128
(128 `op_Division` 8) <= plain_num_bytes /\ plain_num_bytes < va_mul_nat len128x6 (128
`op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8) + 128 `op_Division` 8) /\
(va_mul_nat (va_get_reg64 rRdx va_s0) (128 `op_Division` 8) <= va_get_reg64 rRsi va_s0 /\
va_get_reg64 rRsi va_s0 < va_mul_nat (va_get_reg64 rRdx va_s0) (128 `op_Division` 8) + 128
`op_Division` 8) /\ aes_reqs alg key round_keys keys_b (va_get_reg64 rRcx va_s0)
(va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ pclmulqdq_enabled /\
Vale.AES.GHash.hkeys_reqs_priv (Vale.X64.Decls.s128 (va_get_mem_heaplet 0 va_s0) hkeys_b)
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key
(Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0)))) /\ (forall (va_x_mem:vale_heap)
(va_x_rax:nat64) (va_x_rbx:nat64) (va_x_rcx:nat64) (va_x_rdx:nat64) (va_x_rdi:nat64)
(va_x_rsi:nat64) (va_x_rbp:nat64) (va_x_r8:nat64) (va_x_r9:nat64) (va_x_r10:nat64)
(va_x_r11:nat64) (va_x_r12:nat64) (va_x_r13:nat64) (va_x_r14:nat64) (va_x_r15:nat64)
(va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32)
(va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm7:quad32) (va_x_xmm8:quad32) (va_x_xmm9:quad32)
(va_x_xmm10:quad32) (va_x_xmm11:quad32) (va_x_xmm12:quad32) (va_x_xmm13:quad32)
(va_x_xmm14:quad32) (va_x_xmm15:quad32) (va_x_heap1:vale_heap) (va_x_heap2:vale_heap)
(va_x_heap3:vale_heap) (va_x_heap5:vale_heap) (va_x_heap6:vale_heap)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_mem_heaplet 6
va_x_heap6 (va_upd_mem_heaplet 5 va_x_heap5 (va_upd_mem_heaplet 3 va_x_heap3
(va_upd_mem_heaplet 2 va_x_heap2 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_xmm 15 va_x_xmm15
(va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13 (va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11
va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9 va_x_xmm9 (va_upd_xmm 8 va_x_xmm8
(va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4
(va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0
(va_upd_reg64 rR15 va_x_r15 (va_upd_reg64 rR14 va_x_r14 (va_upd_reg64 rR13 va_x_r13
(va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rR11 va_x_r11 (va_upd_reg64 rR10 va_x_r10
(va_upd_reg64 rR9 va_x_r9 (va_upd_reg64 rR8 va_x_r8 (va_upd_reg64 rRbp va_x_rbp (va_upd_reg64
rRsi va_x_rsi (va_upd_reg64 rRdi va_x_rdi (va_upd_reg64 rRdx va_x_rdx (va_upd_reg64 rRcx
va_x_rcx (va_upd_reg64 rRbx va_x_rbx (va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem
va_s0))))))))))))))))))))))))))))))))))))) in va_get_ok va_sM /\ (let
(abytes_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
offset + 0) (va_get_stack va_s0) in let (in128x6_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 8) (va_get_stack va_s0) in
let (out128x6_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + offset + 16) (va_get_stack va_s0) in let (len128x6:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 24) (va_get_stack va_s0) in
let (in128_ptr:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0
+ offset + 32) (va_get_stack va_s0) in let (out128_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 40) (va_get_stack va_s0) in
let (len128:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
offset + 48) (va_get_stack va_s0) in let (inout_ptr:Vale.X64.Memory.nat64) =
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + offset + 56) (va_get_stack va_s0) in
let (plain_num_bytes:Vale.X64.Memory.nat64) = Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + offset + 64) (va_get_stack va_s0) in let (h_LE:Vale.Def.Types_s.quad32) =
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 2
(va_get_mem_heaplet 0 va_s0)) in Vale.X64.Decls.modifies_buffer128 out128_b (va_get_mem_heaplet
1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ Vale.X64.Decls.modifies_buffer128 iv_b
(va_get_mem_heaplet 2 va_s0) (va_get_mem_heaplet 2 va_sM) /\ Vale.X64.Decls.modifies_buffer128
scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) /\
Vale.X64.Decls.modifies_buffer128 inout_b (va_get_mem_heaplet 5 va_s0) (va_get_mem_heaplet 5
va_sM) /\ Vale.X64.Decls.modifies_buffer128 out128x6_b (va_get_mem_heaplet 6 va_s0)
(va_get_mem_heaplet 6 va_sM) /\ plain_num_bytes < pow2_32 /\ va_get_reg64 rRsi va_s0 < pow2_32
/\ (let iv_BE = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem_heaplet 2 va_s0) in let
(ctr_BE_1:quad32) = iv_BE in let (ctr_BE_2:quad32) = Vale.AES.GCTR_s.inc32 iv_BE 1 in let
(plain_in:(seq quad32)) = va_if (plain_num_bytes > (len128x6 + len128) `op_Multiply` 128
`op_Division` 8) (fun _ -> FStar.Seq.Base.append #Vale.X64.Decls.quad32 (FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s0) in128x6_b)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in128_b)) (Vale.X64.Decls.s128
(va_get_mem_heaplet 5 va_s0) inout_b)) (fun _ -> FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s0) in128x6_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in128_b)) in let (cipher_out:(seq quad32)) = va_if
(plain_num_bytes > (len128x6 + len128) `op_Multiply` 128 `op_Division` 8) (fun _ ->
FStar.Seq.Base.append #Vale.X64.Decls.quad32 (FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_sM) out128x6_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_sM) out128_b)) (Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_sM)
inout_b)) (fun _ -> FStar.Seq.Base.append #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128
(va_get_mem_heaplet 6 va_sM) out128x6_b) (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM)
out128_b)) in let (cipher_bound:nat) = va_if (plain_num_bytes > (len128x6 + len128)
`op_Multiply` 128 `op_Division` 8) (fun _ -> len128x6 + len128 + 1) (fun _ -> len128x6 +
len128) in Vale.AES.GCTR.gctr_partial alg cipher_bound plain_in cipher_out key ctr_BE_2 /\ (let
(length_quad:quad32) = Vale.Def.Types_s.reverse_bytes_quad32 (Vale.Def.Types_s.insert_nat64
(Vale.Def.Types_s.insert_nat64 (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0) (8
`op_Multiply` va_get_reg64 rRsi va_s0) 1) (8 `op_Multiply` plain_num_bytes) 0) in let
(raw_auth_quads:(seq quad32)) = va_if (va_get_reg64 rRsi va_s0 > va_get_reg64 rRdx va_s0
`op_Multiply` 128 `op_Division` 8) (fun _ -> FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) auth_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 7 va_s0) abytes_b)) (fun _ -> Vale.X64.Decls.s128 (va_get_mem_heaplet 1
va_s0) auth_b) in let (auth_input_bytes:(seq nat8)) = FStar.Seq.Base.slice
#Vale.Def.Types_s.nat8 (Vale.Def.Types_s.le_seq_quad32_to_bytes raw_auth_quads) 0 (va_get_reg64
rRsi va_s0) in let (padded_auth_bytes:(seq nat8)) = Vale.AES.GCTR_s.pad_to_128_bits
auth_input_bytes in let (auth_quad_seq:(seq quad32)) = Vale.Def.Types_s.le_bytes_to_seq_quad32
padded_auth_bytes in let (raw_quad_seq:(seq quad32)) = FStar.Seq.Base.append #quad32
(FStar.Seq.Base.append #quad32 auth_quad_seq (Vale.X64.Decls.s128 (va_get_mem_heaplet 6 va_s0)
in128x6_b)) (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in128_b) in let (total_bytes:nat)
= FStar.Seq.Base.length #quad32 auth_quad_seq `op_Multiply` 16 + plain_num_bytes in let
(raw_quad_seq:(seq quad32)) = va_if (plain_num_bytes > (len128x6 + len128) `op_Multiply` 128
`op_Division` 8) (fun _ -> let (ab:(seq nat8)) = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes (FStar.Seq.Base.append #quad32 raw_quad_seq
(Vale.X64.Decls.s128 (va_get_mem_heaplet 5 va_s0) inout_b))) 0 total_bytes in let (pb:(seq
nat8)) = Vale.AES.GCTR_s.pad_to_128_bits ab in Vale.Def.Types_s.le_bytes_to_seq_quad32 pb) (fun
_ -> raw_quad_seq) in let (auth_quad_seq:(seq quad32)) = FStar.Seq.Base.append #quad32
raw_quad_seq (FStar.Seq.Base.create #quad32 1 length_quad) in va_get_xmm 8 va_sM ==
Vale.AES.GCTR_s.gctr_encrypt_block ctr_BE_1 (Vale.AES.GHash_s.ghash_LE h_LE auth_quad_seq) alg
key 0))) ==> va_k va_sM (())))
val va_wpProof_Gcm_blocks : alg:algorithm -> offset:int -> auth_b:buffer128 -> abytes_b:buffer128
-> in128x6_b:buffer128 -> out128x6_b:buffer128 -> in128_b:buffer128 -> out128_b:buffer128 ->
inout_b:buffer128 -> iv_b:buffer128 -> scratch_b:buffer128 -> key:(seq nat32) -> round_keys:(seq
quad32) -> keys_b:buffer128 -> hkeys_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit ->
Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Gcm_blocks alg offset auth_b abytes_b in128x6_b out128x6_b
in128_b out128_b inout_b iv_b scratch_b key round_keys keys_b hkeys_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gcm_blocks alg offset) ([va_Mod_flags;
va_Mod_mem_heaplet 6; va_Mod_mem_heaplet 5; va_Mod_mem_heaplet 3; va_Mod_mem_heaplet 2;
va_Mod_mem_heaplet 1; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm
11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5;
va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR15;
va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rR10;
va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRbp; va_Mod_reg64 rRsi; va_Mod_reg64 rRdi;
va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_mem]) va_s0
va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Stack.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Lib.Meta.fsti.checked",
"Vale.Lib.Basic.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.GHash.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.GCTR.fsti.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.X64.AESopt2.fsti.checked",
"Vale.AES.X64.AESopt.fsti.checked",
"Vale.AES.X64.AESGCM.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.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.GCM.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GCMdecryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Basic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AESopt2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AESGCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AESopt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM",
"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.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"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.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": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AESopt2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AESGCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AESopt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM",
"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.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"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.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": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 1000,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
offset: Prims.int ->
auth_b: Vale.X64.Memory.buffer128 ->
abytes_b: Vale.X64.Memory.buffer128 ->
in128x6_b: Vale.X64.Memory.buffer128 ->
out128x6_b: Vale.X64.Memory.buffer128 ->
in128_b: Vale.X64.Memory.buffer128 ->
out128_b: Vale.X64.Memory.buffer128 ->
inout_b: Vale.X64.Memory.buffer128 ->
iv_b: Vale.X64.Memory.buffer128 ->
scratch_b: Vale.X64.Memory.buffer128 ->
key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 ->
round_keys: FStar.Seq.Base.seq Vale.X64.Decls.quad32 ->
keys_b: Vale.X64.Memory.buffer128 ->
hkeys_b: Vale.X64.Memory.buffer128 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Prims.Ghost ((Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel) * Prims.unit) | Prims.Ghost | [] | [] | [
"Vale.AES.AES_common_s.algorithm",
"Prims.int",
"Vale.X64.Memory.buffer128",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat32",
"Vale.X64.Decls.quad32",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Vale.X64.Decls.va_fuel",
"FStar.Pervasives.Native.Mktuple3",
"Vale.X64.QuickCode.va_lemma_norm_mods",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_flags",
"Vale.X64.QuickCode.va_Mod_mem_heaplet",
"Vale.X64.QuickCode.va_Mod_xmm",
"Vale.X64.QuickCode.va_Mod_reg64",
"Vale.X64.Machine_s.rR15",
"Vale.X64.Machine_s.rR14",
"Vale.X64.Machine_s.rR13",
"Vale.X64.Machine_s.rR12",
"Vale.X64.Machine_s.rR11",
"Vale.X64.Machine_s.rR10",
"Vale.X64.Machine_s.rR9",
"Vale.X64.Machine_s.rR8",
"Vale.X64.Machine_s.rRbp",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rRdi",
"Vale.X64.Machine_s.rRdx",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRbx",
"Vale.X64.Machine_s.rRax",
"Vale.X64.QuickCode.va_Mod_mem",
"Prims.Nil",
"Prims._assert",
"Vale.X64.Decls.va_state_eq",
"Vale.X64.Decls.va_update_flags",
"Vale.X64.Decls.va_update_mem_heaplet",
"Vale.X64.Decls.va_update_xmm",
"Vale.X64.Decls.va_update_reg64",
"Vale.X64.Decls.va_update_ok",
"Vale.X64.Decls.va_update_mem",
"Vale.X64.Decls.va_lemma_upd_update",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.State.vale_state",
"Vale.AES.X64.GCMdecryptOpt.va_lemma_Gcm_blocks",
"Vale.AES.X64.GCMdecryptOpt.va_code_Gcm_blocks"
] | [] | false | false | false | false | false | let va_wpProof_Gcm_blocks
alg
offset
auth_b
abytes_b
in128x6_b
out128x6_b
in128_b
out128_b
inout_b
iv_b
scratch_b
key
round_keys
keys_b
hkeys_b
va_s0
va_k
=
| let va_sM, va_f0 =
va_lemma_Gcm_blocks (va_code_Gcm_blocks alg offset) va_s0 alg offset auth_b abytes_b in128x6_b
out128x6_b in128_b out128_b inout_b iv_b scratch_b key round_keys keys_b hkeys_b
in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM
(va_update_flags va_sM
(va_update_mem_heaplet 6
va_sM
(va_update_mem_heaplet 5
va_sM
(va_update_mem_heaplet 3
va_sM
(va_update_mem_heaplet 2
va_sM
(va_update_mem_heaplet 1
va_sM
(va_update_xmm 15
va_sM
(va_update_xmm 14
va_sM
(va_update_xmm 13
va_sM
(va_update_xmm 12
va_sM
(va_update_xmm 11
va_sM
(va_update_xmm 10
va_sM
(va_update_xmm 9
va_sM
(va_update_xmm 8
va_sM
(va_update_xmm 7
va_sM
(va_update_xmm 6
va_sM
(va_update_xmm 5
va_sM
(va_update_xmm 4
va_sM
(va_update_xmm 3
va_sM
(va_update_xmm 2
va_sM
(va_update_xmm
1
va_sM
(va_update_xmm
0
va_sM
(va_update_reg64
rR15
va_sM
(va_update_reg64
rR14
va_sM
(
va_update_reg64
rR13
va_sM
(
va_update_reg64
rR12
va_sM
(
va_update_reg64
rR11
va_sM
(
va_update_reg64
rR10
va_sM
(
va_update_reg64
rR9
va_sM
(
va_update_reg64
rR8
va_sM
(
va_update_reg64
rRbp
va_sM
(
va_update_reg64
rRsi
va_sM
(
va_update_reg64
rRdi
va_sM
(
va_update_reg64
rRdx
va_sM
(
va_update_reg64
rRcx
va_sM
(
va_update_reg64
rRbx
va_sM
(
va_update_reg64
rRax
va_sM
(
va_update_ok
va_sM
(
va_update_mem
va_sM
va_s0
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
))
))))))))))
)))))))))))));
va_lemma_norm_mods ([
va_Mod_flags; va_Mod_mem_heaplet 6; va_Mod_mem_heaplet 5; va_Mod_mem_heaplet 3;
va_Mod_mem_heaplet 2; va_Mod_mem_heaplet 1; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13;
va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7;
va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_xmm 0; va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12;
va_Mod_reg64 rR11; va_Mod_reg64 rR10; va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRbp;
va_Mod_reg64 rRsi; va_Mod_reg64 rRdi; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx;
va_Mod_reg64 rRax; va_Mod_mem
])
va_sM
va_s0;
let va_g = () in
(va_sM, va_f0, va_g) | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.term_to_string' | val term_to_string' (level: string) (t: term) : T.Tac string | val term_to_string' (level: string) (t: term) : T.Tac string | let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 125,
"start_col": 0,
"start_line": 75
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
) | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | level: Prims.string -> t: Pulse.Syntax.Base.term -> FStar.Tactics.Effect.Tac Prims.string | FStar.Tactics.Effect.Tac | [] | [
"binder_to_string_paren",
"term_to_string'"
] | [
"Prims.string",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.term_to_string'",
"Pulse.Syntax.Printer.indent",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Prims.list",
"FStar.String.concat",
"FStar.Tactics.Util.map",
"Pulse.Syntax.Printer.binder_to_string_paren",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Printer.collect_binders",
"Pulse.Syntax.Base.uu___is_Tm_ExistsSL",
"Pulse.Syntax.Base.uu___is_Tm_ForallSL",
"Pulse.Syntax.Base.host_term",
"FStar.Stubs.Tactics.V2.Builtins.term_to_string"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec term_to_string' (level: string) (t: term) : T.Tac string =
| match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p -> sprintf "pure (%s)" (term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s" (term_to_string' level p1) level (term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is -> sprintf "add_inv %s %s" (term_to_string' level i) (term_to_string' level is)
| Tm_Inv i -> sprintf "inv %s" (term_to_string' level i)
| Tm_FStar t -> T.term_to_string t | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.comp_to_string | val comp_to_string (c:comp) : T.Tac string | val comp_to_string (c:comp) : T.Tac string | let comp_to_string (c:comp)
: T.Tac string
= match c with
| C_Tot t ->
sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post) | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 217,
"start_col": 0,
"start_line": 193
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral"
let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens) | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: Pulse.Syntax.Base.comp -> FStar.Tactics.Effect.Tac Prims.string | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"FStar.Printf.sprintf",
"Prims.string",
"Pulse.Syntax.Printer.term_to_string",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post",
"Pulse.Syntax.Base.observability",
"Pulse.Syntax.Printer.observability_to_string"
] | [] | false | true | false | false | false | let comp_to_string (c: comp) : T.Tac string =
| match c with
| C_Tot t -> sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post) | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.print_st_head | val print_st_head (t:st_term) : string | val print_st_head (t:st_term) : string | let rec print_st_head (t:st_term)
: Tot string (decreases t) =
match t.term with
| Tm_Abs _ -> "Abs"
| Tm_Return p -> print_head p.term
| Tm_Bind _ -> "Bind"
| Tm_TotBind _ -> "TotBind"
| Tm_If _ -> "If"
| Tm_Match _ -> "Match"
| Tm_While _ -> "While"
| Tm_Admit _ -> "Admit"
| Tm_Unreachable -> "Unreachable"
| Tm_Par _ -> "Par"
| Tm_Rewrite _ -> "Rewrite"
| Tm_WithLocal _ -> "WithLocal"
| Tm_WithLocalArray _ -> "WithLocalArray"
| Tm_STApp { head = p } -> print_head p
| Tm_IntroPure _ -> "IntroPure"
| Tm_IntroExists _ -> "IntroExists"
| Tm_ElimExists _ -> "ElimExists"
| Tm_ProofHintWithBinders _ -> "AssertWithBinders"
| Tm_WithInv _ -> "WithInv"
and print_head (t:term) =
match t with
// | Tm_FVar fv
// | Tm_UInst fv _ -> String.concat "." fv.fv_name
// | Tm_PureApp head _ _ -> print_head head
| _ -> "<pure term>" | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 22,
"end_line": 507,
"start_col": 0,
"start_line": 480
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral"
let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens)
let comp_to_string (c:comp)
: T.Tac string
= match c with
| C_Tot t ->
sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
let term_opt_to_string (t:option term)
: T.Tac string
= match t with
| None -> ""
| Some t -> term_to_string t
let term_list_to_string (sep:string) (t:list term)
: T.Tac string
= String.concat sep (T.map term_to_string t)
let rec st_term_to_string' (level:string) (t:st_term)
: T.Tac string
= match t.term with
| Tm_Return { insert_eq; term } ->
sprintf "return_%s %s"
(if insert_eq then "" else "_noeq")
(term_to_string term)
| Tm_STApp {head; arg_qual; arg } ->
sprintf "(%s%s %s%s)"
(if dbg_printing then "<stapp>" else "")
(term_to_string head)
(qual_to_string arg_qual)
(term_to_string arg)
| Tm_Bind { binder; head; body } ->
// if T.unseal binder.binder_ppname.name = "_"
// then sprintf "%s;\n%s%s"
// (st_term_to_string' level head)
// level
// (st_term_to_string' level body)
// else (
sprintf "let %s = %s;\n%s%s"
(binder_to_string binder)
(st_term_to_string' level head)
level
(st_term_to_string' level body)
// )
| Tm_TotBind { head; binder; body } ->
sprintf "let tot %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string head)
level
(st_term_to_string' level body)
| Tm_Abs { b; q; ascription=c; body } ->
sprintf "(fun (%s%s)\n%s\n ({\n%s%s\n}%s)"
(qual_to_string q)
(binder_to_string b)
(match c.annotated with | None -> "" | Some c -> comp_to_string c)
(indent level)
(st_term_to_string' (indent level) body)
(match c.elaborated with | None -> "" | Some c -> " <: " ^ comp_to_string c)
| Tm_If { b; then_; else_ } ->
sprintf "if (%s)\n%s{\n%s%s\n%s}\n%selse\n%s{\n%s%s\n%s}"
(term_to_string b)
level
(indent level)
(st_term_to_string' (indent level) then_)
level
level
level
(indent level)
(st_term_to_string' (indent level) else_)
level
| Tm_Match {sc; brs} ->
sprintf "match (%s) with %s"
(term_to_string sc)
(branches_to_string brs)
| Tm_IntroPure { p } ->
sprintf "introduce pure (\n%s%s)"
(indent level)
(term_to_string' (indent level) p)
| Tm_ElimExists { p } ->
sprintf "elim_exists %s"
(term_to_string p)
| Tm_IntroExists { p; witnesses } ->
sprintf "introduce\n%s%s\n%swith %s"
(indent level)
(term_to_string' (indent level) p)
level
(term_list_to_string " " witnesses)
| Tm_While { invariant; condition; body } ->
sprintf "while (%s)\n%sinvariant %s\n%s{\n%s%s\n%s}"
(st_term_to_string' level condition)
level
(term_to_string invariant)
level
(indent level)
(st_term_to_string' (indent level) body)
level
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
sprintf "par (<%s> (%s) <%s) (<%s> (%s) <%s)"
(term_to_string pre1)
(st_term_to_string' level body1)
(term_to_string post1)
(term_to_string pre2)
(st_term_to_string' level body2)
(term_to_string post2)
| Tm_Rewrite { t1; t2 } ->
sprintf "rewrite %s %s"
(term_to_string t1)
(term_to_string t2)
| Tm_WithLocal { binder; initializer; body } ->
sprintf "let mut %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
level
(st_term_to_string' level body)
| Tm_WithLocalArray { binder; initializer; length; body } ->
sprintf "let mut %s = [| %s; %s |]\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
(term_to_string length)
level
(st_term_to_string' level body)
| Tm_Admit { ctag; u; typ; post } ->
sprintf "%s<%s> %s%s"
(match ctag with
| STT -> "stt_admit"
| STT_Atomic -> "stt_atomic_admit"
| STT_Ghost -> "stt_ghost_admit")
(universe_to_string 0 u)
(term_to_string typ)
(match post with
| None -> ""
| Some post -> sprintf " %s" (term_to_string post))
| Tm_Unreachable -> "unreachable ()"
| Tm_ProofHintWithBinders { binders; hint_type; t} ->
let with_prefix =
match binders with
| [] -> ""
| _ -> sprintf "with %s." (String.concat " " (T.map binder_to_string binders))
in
let names_to_string = function
| None -> ""
| Some l -> sprintf " [%s]" (String.concat "; " l)
in
let ht, p =
match hint_type with
| ASSERT { p } -> "assert", term_to_string p
| UNFOLD { names; p } -> sprintf "unfold%s" (names_to_string names), term_to_string p
| FOLD { names; p } -> sprintf "fold%s" (names_to_string names), term_to_string p
| RENAME { pairs; goal } ->
sprintf "rewrite each %s"
(String.concat ", "
(T.map
(fun (x, y) -> sprintf "%s as %s" (term_to_string x) (term_to_string y))
pairs)),
(match goal with
| None -> ""
| Some t -> sprintf " in %s" (term_to_string t))
| REWRITE { t1; t2 } ->
sprintf "rewrite %s as %s" (term_to_string t1) (term_to_string t2), ""
| WILD -> "_", ""
| SHOW_PROOF_STATE _ -> "show_proof_state", ""
in
sprintf "%s %s %s; %s" with_prefix ht p
(st_term_to_string' level t)
| Tm_WithInv { name; body; returns_inv } ->
sprintf "with_inv %s %s %s"
(term_to_string name)
(st_term_to_string' level body)
(match returns_inv with
| None -> ""
| Some (b, t) ->
sprintf "\nreturns %s\nensures %s"
(binder_to_string b)
(term_to_string t))
and branches_to_string brs : T.Tac _ =
match brs with
| [] -> ""
| b::bs -> branch_to_string b ^ branches_to_string bs
and branch_to_string br : T.Tac _ =
let (pat, e) = br in
Printf.sprintf "{ %s -> %s }"
(pattern_to_string pat)
(st_term_to_string' "" e)
and pattern_to_string (p:pattern) : T.Tac string =
match p with
| Pat_Cons fv pats ->
Printf.sprintf "(%s %s)"
(String.concat "." fv.fv_name)
(String.concat " " (T.map (fun (p, _) -> pattern_to_string p) pats))
| Pat_Constant c ->
"<constant>"
| Pat_Var x _ ->
T.unseal x
| Pat_Dot_Term None ->
""
| Pat_Dot_Term (Some t) ->
Printf.sprintf "(.??)" //%s)" (term_to_string t)
let st_term_to_string t = st_term_to_string' "" t
let tag_of_term (t:term) =
match t.t with
| Tm_Emp -> "Tm_Emp"
| Tm_Pure _ -> "Tm_Pure"
| Tm_Star _ _ -> "Tm_Star"
| Tm_ExistsSL _ _ _ -> "Tm_ExistsSL"
| Tm_ForallSL _ _ _ -> "Tm_ForallSL"
| Tm_VProp -> "Tm_VProp"
| Tm_Inames -> "Tm_Inames"
| Tm_EmpInames -> "Tm_EmpInames"
| Tm_Unknown -> "Tm_Unknown"
| Tm_FStar _ -> "Tm_FStar"
| Tm_AddInv _ _ -> "Tm_AddInv"
| Tm_Inv _ -> "Tm_Inv"
let tag_of_st_term (t:st_term) =
match t.term with
| Tm_Return _ -> "Tm_Return"
| Tm_Abs _ -> "Tm_Abs"
| Tm_STApp _ -> "Tm_STApp"
| Tm_Bind _ -> "Tm_Bind"
| Tm_TotBind _ -> "Tm_TotBind"
| Tm_If _ -> "Tm_If"
| Tm_Match _ -> "Tm_Match"
| Tm_IntroPure _ -> "Tm_IntroPure"
| Tm_ElimExists _ -> "Tm_ElimExists"
| Tm_IntroExists _ -> "Tm_IntroExists"
| Tm_While _ -> "Tm_While"
| Tm_Par _ -> "Tm_Par"
| Tm_WithLocal _ -> "Tm_WithLocal"
| Tm_WithLocalArray _ -> "Tm_WithLocalArray"
| Tm_Rewrite _ -> "Tm_Rewrite"
| Tm_Admit _ -> "Tm_Admit"
| Tm_Unreachable -> "Tm_Unreachable"
| Tm_ProofHintWithBinders _ -> "Tm_ProofHintWithBinders"
| Tm_WithInv _ -> "Tm_WithInv"
let tag_of_comp (c:comp) : T.Tac string =
match c with
| C_Tot _ -> "Total"
| C_ST _ -> "ST"
| C_STAtomic i obs _ ->
Printf.sprintf "%s %s" (observability_to_string obs) (term_to_string i)
| C_STGhost _ ->
"Ghost" | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.st_term -> Prims.Tot Prims.string | Prims.Tot | [
"",
"total"
] | [
"print_st_head",
"print_head"
] | [
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.__proj__Mkst_term__item__term",
"Pulse.Syntax.Base.st_term'__Tm_Abs__payload",
"Pulse.Syntax.Base.st_term'__Tm_Return__payload",
"Pulse.Syntax.Printer.print_head",
"Pulse.Syntax.Base.__proj__Mkst_term'__Tm_Return__payload__item__term",
"Pulse.Syntax.Base.st_term'__Tm_Bind__payload",
"Pulse.Syntax.Base.st_term'__Tm_TotBind__payload",
"Pulse.Syntax.Base.st_term'__Tm_If__payload",
"Pulse.Syntax.Base.st_term'__Tm_Match__payload",
"Pulse.Syntax.Base.st_term'__Tm_While__payload",
"Pulse.Syntax.Base.st_term'__Tm_Admit__payload",
"Pulse.Syntax.Base.st_term'__Tm_Par__payload",
"Pulse.Syntax.Base.st_term'__Tm_Rewrite__payload",
"Pulse.Syntax.Base.st_term'__Tm_WithLocal__payload",
"Pulse.Syntax.Base.st_term'__Tm_WithLocalArray__payload",
"Pulse.Syntax.Base.term",
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Base.st_term'__Tm_IntroPure__payload",
"Pulse.Syntax.Base.st_term'__Tm_IntroExists__payload",
"Pulse.Syntax.Base.st_term'__Tm_ElimExists__payload",
"Pulse.Syntax.Base.st_term'__Tm_ProofHintWithBinders__payload",
"Pulse.Syntax.Base.st_term'__Tm_WithInv__payload",
"Prims.string"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec print_st_head (t: st_term) : Tot string (decreases t) =
| match t.term with
| Tm_Abs _ -> "Abs"
| Tm_Return p -> print_head p.term
| Tm_Bind _ -> "Bind"
| Tm_TotBind _ -> "TotBind"
| Tm_If _ -> "If"
| Tm_Match _ -> "Match"
| Tm_While _ -> "While"
| Tm_Admit _ -> "Admit"
| Tm_Unreachable -> "Unreachable"
| Tm_Par _ -> "Par"
| Tm_Rewrite _ -> "Rewrite"
| Tm_WithLocal _ -> "WithLocal"
| Tm_WithLocalArray _ -> "WithLocalArray"
| Tm_STApp { head = p } -> print_head p
| Tm_IntroPure _ -> "IntroPure"
| Tm_IntroExists _ -> "IntroExists"
| Tm_ElimExists _ -> "ElimExists"
| Tm_ProofHintWithBinders _ -> "AssertWithBinders"
| Tm_WithInv _ -> "WithInv" | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.binder_to_string_paren | val binder_to_string_paren (b: binder) : T.Tac string | val binder_to_string_paren (b: binder) : T.Tac string | let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 125,
"start_col": 0,
"start_line": 75
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
) | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Pulse.Syntax.Base.binder -> FStar.Tactics.Effect.Tac Prims.string | FStar.Tactics.Effect.Tac | [] | [
"binder_to_string_paren",
"term_to_string'"
] | [
"Pulse.Syntax.Base.binder",
"Prims.string",
"FStar.Printf.sprintf",
"Prims.list",
"Pulse.Syntax.Base.term",
"FStar.String.concat",
"FStar.Tactics.Util.map",
"Pulse.Syntax.Printer.term_to_string'",
"FStar.Tactics.Unseal.unseal",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_attrs",
"Pulse.Syntax.Base.__proj__Mkppname__item__name",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ppname",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec binder_to_string_paren (b: binder) : T.Tac string =
| sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty) | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.print_skel | val print_skel (t:st_term) : string | val print_skel (t:st_term) : string | let rec print_skel (t:st_term) =
match t.term with
| Tm_Abs { body } -> Printf.sprintf "(fun _ -> %s)" (print_skel body)
| Tm_Return { term = p } -> print_head p
| Tm_Bind { head=e1; body=e2 } -> Printf.sprintf "(Bind %s %s)" (print_skel e1) (print_skel e2)
| Tm_TotBind { body=e2 } -> Printf.sprintf "(TotBind _ %s)" (print_skel e2)
| Tm_If _ -> "If"
| Tm_Match _ -> "Match"
| Tm_While _ -> "While"
| Tm_Admit _ -> "Admit"
| Tm_Unreachable -> "Unreachable"
| Tm_Par _ -> "Par"
| Tm_Rewrite _ -> "Rewrite"
| Tm_WithLocal _ -> "WithLocal"
| Tm_WithLocalArray _ -> "WithLocalArray"
| Tm_STApp { head = p } -> print_head p
| Tm_IntroPure _ -> "IntroPure"
| Tm_IntroExists _ -> "IntroExists"
| Tm_ElimExists _ -> "ElimExists"
| Tm_ProofHintWithBinders _ -> "AssertWithBinders"
| Tm_WithInv _ -> "WithInv" | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 29,
"end_line": 530,
"start_col": 0,
"start_line": 510
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral"
let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens)
let comp_to_string (c:comp)
: T.Tac string
= match c with
| C_Tot t ->
sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
let term_opt_to_string (t:option term)
: T.Tac string
= match t with
| None -> ""
| Some t -> term_to_string t
let term_list_to_string (sep:string) (t:list term)
: T.Tac string
= String.concat sep (T.map term_to_string t)
let rec st_term_to_string' (level:string) (t:st_term)
: T.Tac string
= match t.term with
| Tm_Return { insert_eq; term } ->
sprintf "return_%s %s"
(if insert_eq then "" else "_noeq")
(term_to_string term)
| Tm_STApp {head; arg_qual; arg } ->
sprintf "(%s%s %s%s)"
(if dbg_printing then "<stapp>" else "")
(term_to_string head)
(qual_to_string arg_qual)
(term_to_string arg)
| Tm_Bind { binder; head; body } ->
// if T.unseal binder.binder_ppname.name = "_"
// then sprintf "%s;\n%s%s"
// (st_term_to_string' level head)
// level
// (st_term_to_string' level body)
// else (
sprintf "let %s = %s;\n%s%s"
(binder_to_string binder)
(st_term_to_string' level head)
level
(st_term_to_string' level body)
// )
| Tm_TotBind { head; binder; body } ->
sprintf "let tot %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string head)
level
(st_term_to_string' level body)
| Tm_Abs { b; q; ascription=c; body } ->
sprintf "(fun (%s%s)\n%s\n ({\n%s%s\n}%s)"
(qual_to_string q)
(binder_to_string b)
(match c.annotated with | None -> "" | Some c -> comp_to_string c)
(indent level)
(st_term_to_string' (indent level) body)
(match c.elaborated with | None -> "" | Some c -> " <: " ^ comp_to_string c)
| Tm_If { b; then_; else_ } ->
sprintf "if (%s)\n%s{\n%s%s\n%s}\n%selse\n%s{\n%s%s\n%s}"
(term_to_string b)
level
(indent level)
(st_term_to_string' (indent level) then_)
level
level
level
(indent level)
(st_term_to_string' (indent level) else_)
level
| Tm_Match {sc; brs} ->
sprintf "match (%s) with %s"
(term_to_string sc)
(branches_to_string brs)
| Tm_IntroPure { p } ->
sprintf "introduce pure (\n%s%s)"
(indent level)
(term_to_string' (indent level) p)
| Tm_ElimExists { p } ->
sprintf "elim_exists %s"
(term_to_string p)
| Tm_IntroExists { p; witnesses } ->
sprintf "introduce\n%s%s\n%swith %s"
(indent level)
(term_to_string' (indent level) p)
level
(term_list_to_string " " witnesses)
| Tm_While { invariant; condition; body } ->
sprintf "while (%s)\n%sinvariant %s\n%s{\n%s%s\n%s}"
(st_term_to_string' level condition)
level
(term_to_string invariant)
level
(indent level)
(st_term_to_string' (indent level) body)
level
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
sprintf "par (<%s> (%s) <%s) (<%s> (%s) <%s)"
(term_to_string pre1)
(st_term_to_string' level body1)
(term_to_string post1)
(term_to_string pre2)
(st_term_to_string' level body2)
(term_to_string post2)
| Tm_Rewrite { t1; t2 } ->
sprintf "rewrite %s %s"
(term_to_string t1)
(term_to_string t2)
| Tm_WithLocal { binder; initializer; body } ->
sprintf "let mut %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
level
(st_term_to_string' level body)
| Tm_WithLocalArray { binder; initializer; length; body } ->
sprintf "let mut %s = [| %s; %s |]\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
(term_to_string length)
level
(st_term_to_string' level body)
| Tm_Admit { ctag; u; typ; post } ->
sprintf "%s<%s> %s%s"
(match ctag with
| STT -> "stt_admit"
| STT_Atomic -> "stt_atomic_admit"
| STT_Ghost -> "stt_ghost_admit")
(universe_to_string 0 u)
(term_to_string typ)
(match post with
| None -> ""
| Some post -> sprintf " %s" (term_to_string post))
| Tm_Unreachable -> "unreachable ()"
| Tm_ProofHintWithBinders { binders; hint_type; t} ->
let with_prefix =
match binders with
| [] -> ""
| _ -> sprintf "with %s." (String.concat " " (T.map binder_to_string binders))
in
let names_to_string = function
| None -> ""
| Some l -> sprintf " [%s]" (String.concat "; " l)
in
let ht, p =
match hint_type with
| ASSERT { p } -> "assert", term_to_string p
| UNFOLD { names; p } -> sprintf "unfold%s" (names_to_string names), term_to_string p
| FOLD { names; p } -> sprintf "fold%s" (names_to_string names), term_to_string p
| RENAME { pairs; goal } ->
sprintf "rewrite each %s"
(String.concat ", "
(T.map
(fun (x, y) -> sprintf "%s as %s" (term_to_string x) (term_to_string y))
pairs)),
(match goal with
| None -> ""
| Some t -> sprintf " in %s" (term_to_string t))
| REWRITE { t1; t2 } ->
sprintf "rewrite %s as %s" (term_to_string t1) (term_to_string t2), ""
| WILD -> "_", ""
| SHOW_PROOF_STATE _ -> "show_proof_state", ""
in
sprintf "%s %s %s; %s" with_prefix ht p
(st_term_to_string' level t)
| Tm_WithInv { name; body; returns_inv } ->
sprintf "with_inv %s %s %s"
(term_to_string name)
(st_term_to_string' level body)
(match returns_inv with
| None -> ""
| Some (b, t) ->
sprintf "\nreturns %s\nensures %s"
(binder_to_string b)
(term_to_string t))
and branches_to_string brs : T.Tac _ =
match brs with
| [] -> ""
| b::bs -> branch_to_string b ^ branches_to_string bs
and branch_to_string br : T.Tac _ =
let (pat, e) = br in
Printf.sprintf "{ %s -> %s }"
(pattern_to_string pat)
(st_term_to_string' "" e)
and pattern_to_string (p:pattern) : T.Tac string =
match p with
| Pat_Cons fv pats ->
Printf.sprintf "(%s %s)"
(String.concat "." fv.fv_name)
(String.concat " " (T.map (fun (p, _) -> pattern_to_string p) pats))
| Pat_Constant c ->
"<constant>"
| Pat_Var x _ ->
T.unseal x
| Pat_Dot_Term None ->
""
| Pat_Dot_Term (Some t) ->
Printf.sprintf "(.??)" //%s)" (term_to_string t)
let st_term_to_string t = st_term_to_string' "" t
let tag_of_term (t:term) =
match t.t with
| Tm_Emp -> "Tm_Emp"
| Tm_Pure _ -> "Tm_Pure"
| Tm_Star _ _ -> "Tm_Star"
| Tm_ExistsSL _ _ _ -> "Tm_ExistsSL"
| Tm_ForallSL _ _ _ -> "Tm_ForallSL"
| Tm_VProp -> "Tm_VProp"
| Tm_Inames -> "Tm_Inames"
| Tm_EmpInames -> "Tm_EmpInames"
| Tm_Unknown -> "Tm_Unknown"
| Tm_FStar _ -> "Tm_FStar"
| Tm_AddInv _ _ -> "Tm_AddInv"
| Tm_Inv _ -> "Tm_Inv"
let tag_of_st_term (t:st_term) =
match t.term with
| Tm_Return _ -> "Tm_Return"
| Tm_Abs _ -> "Tm_Abs"
| Tm_STApp _ -> "Tm_STApp"
| Tm_Bind _ -> "Tm_Bind"
| Tm_TotBind _ -> "Tm_TotBind"
| Tm_If _ -> "Tm_If"
| Tm_Match _ -> "Tm_Match"
| Tm_IntroPure _ -> "Tm_IntroPure"
| Tm_ElimExists _ -> "Tm_ElimExists"
| Tm_IntroExists _ -> "Tm_IntroExists"
| Tm_While _ -> "Tm_While"
| Tm_Par _ -> "Tm_Par"
| Tm_WithLocal _ -> "Tm_WithLocal"
| Tm_WithLocalArray _ -> "Tm_WithLocalArray"
| Tm_Rewrite _ -> "Tm_Rewrite"
| Tm_Admit _ -> "Tm_Admit"
| Tm_Unreachable -> "Tm_Unreachable"
| Tm_ProofHintWithBinders _ -> "Tm_ProofHintWithBinders"
| Tm_WithInv _ -> "Tm_WithInv"
let tag_of_comp (c:comp) : T.Tac string =
match c with
| C_Tot _ -> "Total"
| C_ST _ -> "ST"
| C_STAtomic i obs _ ->
Printf.sprintf "%s %s" (observability_to_string obs) (term_to_string i)
| C_STGhost _ ->
"Ghost"
let rec print_st_head (t:st_term)
: Tot string (decreases t) =
match t.term with
| Tm_Abs _ -> "Abs"
| Tm_Return p -> print_head p.term
| Tm_Bind _ -> "Bind"
| Tm_TotBind _ -> "TotBind"
| Tm_If _ -> "If"
| Tm_Match _ -> "Match"
| Tm_While _ -> "While"
| Tm_Admit _ -> "Admit"
| Tm_Unreachable -> "Unreachable"
| Tm_Par _ -> "Par"
| Tm_Rewrite _ -> "Rewrite"
| Tm_WithLocal _ -> "WithLocal"
| Tm_WithLocalArray _ -> "WithLocalArray"
| Tm_STApp { head = p } -> print_head p
| Tm_IntroPure _ -> "IntroPure"
| Tm_IntroExists _ -> "IntroExists"
| Tm_ElimExists _ -> "ElimExists"
| Tm_ProofHintWithBinders _ -> "AssertWithBinders"
| Tm_WithInv _ -> "WithInv"
and print_head (t:term) =
match t with
// | Tm_FVar fv
// | Tm_UInst fv _ -> String.concat "." fv.fv_name
// | Tm_PureApp head _ _ -> print_head head
| _ -> "<pure term>" | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.st_term -> Prims.string | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.__proj__Mkst_term__item__term",
"Pulse.Syntax.Base.binder",
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Base.comp_ascription",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.print_skel",
"Pulse.Syntax.Base.term",
"Prims.bool",
"Pulse.Syntax.Printer.print_head",
"Pulse.Syntax.Base.st_term'__Tm_If__payload",
"Pulse.Syntax.Base.st_term'__Tm_Match__payload",
"Pulse.Syntax.Base.st_term'__Tm_While__payload",
"Pulse.Syntax.Base.st_term'__Tm_Admit__payload",
"Pulse.Syntax.Base.st_term'__Tm_Par__payload",
"Pulse.Syntax.Base.st_term'__Tm_Rewrite__payload",
"Pulse.Syntax.Base.st_term'__Tm_WithLocal__payload",
"Pulse.Syntax.Base.st_term'__Tm_WithLocalArray__payload",
"Pulse.Syntax.Base.st_term'__Tm_IntroPure__payload",
"Pulse.Syntax.Base.st_term'__Tm_IntroExists__payload",
"Pulse.Syntax.Base.st_term'__Tm_ElimExists__payload",
"Pulse.Syntax.Base.st_term'__Tm_ProofHintWithBinders__payload",
"Pulse.Syntax.Base.st_term'__Tm_WithInv__payload",
"Prims.string"
] | [
"recursion"
] | false | false | false | true | false | let rec print_skel (t: st_term) =
| match t.term with
| Tm_Abs { body = body } -> Printf.sprintf "(fun _ -> %s)" (print_skel body)
| Tm_Return { term = p } -> print_head p
| Tm_Bind { head = e1 ; body = e2 } -> Printf.sprintf "(Bind %s %s)" (print_skel e1) (print_skel e2)
| Tm_TotBind { body = e2 } -> Printf.sprintf "(TotBind _ %s)" (print_skel e2)
| Tm_If _ -> "If"
| Tm_Match _ -> "Match"
| Tm_While _ -> "While"
| Tm_Admit _ -> "Admit"
| Tm_Unreachable -> "Unreachable"
| Tm_Par _ -> "Par"
| Tm_Rewrite _ -> "Rewrite"
| Tm_WithLocal _ -> "WithLocal"
| Tm_WithLocalArray _ -> "WithLocalArray"
| Tm_STApp { head = p } -> print_head p
| Tm_IntroPure _ -> "IntroPure"
| Tm_IntroExists _ -> "IntroExists"
| Tm_ElimExists _ -> "ElimExists"
| Tm_ProofHintWithBinders _ -> "AssertWithBinders"
| Tm_WithInv _ -> "WithInv" | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.print_head | val print_head : t: Pulse.Syntax.Base.term -> Prims.string | let rec print_st_head (t:st_term)
: Tot string (decreases t) =
match t.term with
| Tm_Abs _ -> "Abs"
| Tm_Return p -> print_head p.term
| Tm_Bind _ -> "Bind"
| Tm_TotBind _ -> "TotBind"
| Tm_If _ -> "If"
| Tm_Match _ -> "Match"
| Tm_While _ -> "While"
| Tm_Admit _ -> "Admit"
| Tm_Unreachable -> "Unreachable"
| Tm_Par _ -> "Par"
| Tm_Rewrite _ -> "Rewrite"
| Tm_WithLocal _ -> "WithLocal"
| Tm_WithLocalArray _ -> "WithLocalArray"
| Tm_STApp { head = p } -> print_head p
| Tm_IntroPure _ -> "IntroPure"
| Tm_IntroExists _ -> "IntroExists"
| Tm_ElimExists _ -> "ElimExists"
| Tm_ProofHintWithBinders _ -> "AssertWithBinders"
| Tm_WithInv _ -> "WithInv"
and print_head (t:term) =
match t with
// | Tm_FVar fv
// | Tm_UInst fv _ -> String.concat "." fv.fv_name
// | Tm_PureApp head _ _ -> print_head head
| _ -> "<pure term>" | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 22,
"end_line": 507,
"start_col": 0,
"start_line": 480
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral"
let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens)
let comp_to_string (c:comp)
: T.Tac string
= match c with
| C_Tot t ->
sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
let term_opt_to_string (t:option term)
: T.Tac string
= match t with
| None -> ""
| Some t -> term_to_string t
let term_list_to_string (sep:string) (t:list term)
: T.Tac string
= String.concat sep (T.map term_to_string t)
let rec st_term_to_string' (level:string) (t:st_term)
: T.Tac string
= match t.term with
| Tm_Return { insert_eq; term } ->
sprintf "return_%s %s"
(if insert_eq then "" else "_noeq")
(term_to_string term)
| Tm_STApp {head; arg_qual; arg } ->
sprintf "(%s%s %s%s)"
(if dbg_printing then "<stapp>" else "")
(term_to_string head)
(qual_to_string arg_qual)
(term_to_string arg)
| Tm_Bind { binder; head; body } ->
// if T.unseal binder.binder_ppname.name = "_"
// then sprintf "%s;\n%s%s"
// (st_term_to_string' level head)
// level
// (st_term_to_string' level body)
// else (
sprintf "let %s = %s;\n%s%s"
(binder_to_string binder)
(st_term_to_string' level head)
level
(st_term_to_string' level body)
// )
| Tm_TotBind { head; binder; body } ->
sprintf "let tot %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string head)
level
(st_term_to_string' level body)
| Tm_Abs { b; q; ascription=c; body } ->
sprintf "(fun (%s%s)\n%s\n ({\n%s%s\n}%s)"
(qual_to_string q)
(binder_to_string b)
(match c.annotated with | None -> "" | Some c -> comp_to_string c)
(indent level)
(st_term_to_string' (indent level) body)
(match c.elaborated with | None -> "" | Some c -> " <: " ^ comp_to_string c)
| Tm_If { b; then_; else_ } ->
sprintf "if (%s)\n%s{\n%s%s\n%s}\n%selse\n%s{\n%s%s\n%s}"
(term_to_string b)
level
(indent level)
(st_term_to_string' (indent level) then_)
level
level
level
(indent level)
(st_term_to_string' (indent level) else_)
level
| Tm_Match {sc; brs} ->
sprintf "match (%s) with %s"
(term_to_string sc)
(branches_to_string brs)
| Tm_IntroPure { p } ->
sprintf "introduce pure (\n%s%s)"
(indent level)
(term_to_string' (indent level) p)
| Tm_ElimExists { p } ->
sprintf "elim_exists %s"
(term_to_string p)
| Tm_IntroExists { p; witnesses } ->
sprintf "introduce\n%s%s\n%swith %s"
(indent level)
(term_to_string' (indent level) p)
level
(term_list_to_string " " witnesses)
| Tm_While { invariant; condition; body } ->
sprintf "while (%s)\n%sinvariant %s\n%s{\n%s%s\n%s}"
(st_term_to_string' level condition)
level
(term_to_string invariant)
level
(indent level)
(st_term_to_string' (indent level) body)
level
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
sprintf "par (<%s> (%s) <%s) (<%s> (%s) <%s)"
(term_to_string pre1)
(st_term_to_string' level body1)
(term_to_string post1)
(term_to_string pre2)
(st_term_to_string' level body2)
(term_to_string post2)
| Tm_Rewrite { t1; t2 } ->
sprintf "rewrite %s %s"
(term_to_string t1)
(term_to_string t2)
| Tm_WithLocal { binder; initializer; body } ->
sprintf "let mut %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
level
(st_term_to_string' level body)
| Tm_WithLocalArray { binder; initializer; length; body } ->
sprintf "let mut %s = [| %s; %s |]\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
(term_to_string length)
level
(st_term_to_string' level body)
| Tm_Admit { ctag; u; typ; post } ->
sprintf "%s<%s> %s%s"
(match ctag with
| STT -> "stt_admit"
| STT_Atomic -> "stt_atomic_admit"
| STT_Ghost -> "stt_ghost_admit")
(universe_to_string 0 u)
(term_to_string typ)
(match post with
| None -> ""
| Some post -> sprintf " %s" (term_to_string post))
| Tm_Unreachable -> "unreachable ()"
| Tm_ProofHintWithBinders { binders; hint_type; t} ->
let with_prefix =
match binders with
| [] -> ""
| _ -> sprintf "with %s." (String.concat " " (T.map binder_to_string binders))
in
let names_to_string = function
| None -> ""
| Some l -> sprintf " [%s]" (String.concat "; " l)
in
let ht, p =
match hint_type with
| ASSERT { p } -> "assert", term_to_string p
| UNFOLD { names; p } -> sprintf "unfold%s" (names_to_string names), term_to_string p
| FOLD { names; p } -> sprintf "fold%s" (names_to_string names), term_to_string p
| RENAME { pairs; goal } ->
sprintf "rewrite each %s"
(String.concat ", "
(T.map
(fun (x, y) -> sprintf "%s as %s" (term_to_string x) (term_to_string y))
pairs)),
(match goal with
| None -> ""
| Some t -> sprintf " in %s" (term_to_string t))
| REWRITE { t1; t2 } ->
sprintf "rewrite %s as %s" (term_to_string t1) (term_to_string t2), ""
| WILD -> "_", ""
| SHOW_PROOF_STATE _ -> "show_proof_state", ""
in
sprintf "%s %s %s; %s" with_prefix ht p
(st_term_to_string' level t)
| Tm_WithInv { name; body; returns_inv } ->
sprintf "with_inv %s %s %s"
(term_to_string name)
(st_term_to_string' level body)
(match returns_inv with
| None -> ""
| Some (b, t) ->
sprintf "\nreturns %s\nensures %s"
(binder_to_string b)
(term_to_string t))
and branches_to_string brs : T.Tac _ =
match brs with
| [] -> ""
| b::bs -> branch_to_string b ^ branches_to_string bs
and branch_to_string br : T.Tac _ =
let (pat, e) = br in
Printf.sprintf "{ %s -> %s }"
(pattern_to_string pat)
(st_term_to_string' "" e)
and pattern_to_string (p:pattern) : T.Tac string =
match p with
| Pat_Cons fv pats ->
Printf.sprintf "(%s %s)"
(String.concat "." fv.fv_name)
(String.concat " " (T.map (fun (p, _) -> pattern_to_string p) pats))
| Pat_Constant c ->
"<constant>"
| Pat_Var x _ ->
T.unseal x
| Pat_Dot_Term None ->
""
| Pat_Dot_Term (Some t) ->
Printf.sprintf "(.??)" //%s)" (term_to_string t)
let st_term_to_string t = st_term_to_string' "" t
let tag_of_term (t:term) =
match t.t with
| Tm_Emp -> "Tm_Emp"
| Tm_Pure _ -> "Tm_Pure"
| Tm_Star _ _ -> "Tm_Star"
| Tm_ExistsSL _ _ _ -> "Tm_ExistsSL"
| Tm_ForallSL _ _ _ -> "Tm_ForallSL"
| Tm_VProp -> "Tm_VProp"
| Tm_Inames -> "Tm_Inames"
| Tm_EmpInames -> "Tm_EmpInames"
| Tm_Unknown -> "Tm_Unknown"
| Tm_FStar _ -> "Tm_FStar"
| Tm_AddInv _ _ -> "Tm_AddInv"
| Tm_Inv _ -> "Tm_Inv"
let tag_of_st_term (t:st_term) =
match t.term with
| Tm_Return _ -> "Tm_Return"
| Tm_Abs _ -> "Tm_Abs"
| Tm_STApp _ -> "Tm_STApp"
| Tm_Bind _ -> "Tm_Bind"
| Tm_TotBind _ -> "Tm_TotBind"
| Tm_If _ -> "Tm_If"
| Tm_Match _ -> "Tm_Match"
| Tm_IntroPure _ -> "Tm_IntroPure"
| Tm_ElimExists _ -> "Tm_ElimExists"
| Tm_IntroExists _ -> "Tm_IntroExists"
| Tm_While _ -> "Tm_While"
| Tm_Par _ -> "Tm_Par"
| Tm_WithLocal _ -> "Tm_WithLocal"
| Tm_WithLocalArray _ -> "Tm_WithLocalArray"
| Tm_Rewrite _ -> "Tm_Rewrite"
| Tm_Admit _ -> "Tm_Admit"
| Tm_Unreachable -> "Tm_Unreachable"
| Tm_ProofHintWithBinders _ -> "Tm_ProofHintWithBinders"
| Tm_WithInv _ -> "Tm_WithInv"
let tag_of_comp (c:comp) : T.Tac string =
match c with
| C_Tot _ -> "Total"
| C_ST _ -> "ST"
| C_STAtomic i obs _ ->
Printf.sprintf "%s %s" (observability_to_string obs) (term_to_string i)
| C_STGhost _ ->
"Ghost" | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> Prims.string | Prims.Tot | [
"total"
] | [
"print_st_head",
"print_head"
] | [
"Pulse.Syntax.Base.term",
"Prims.string"
] | [
"mutual recursion"
] | false | false | false | true | false | let rec print_head (t: term) =
| match t with | _ -> "<pure term>" | false |
|
Steel.ST.BitVector.fst | Steel.ST.BitVector.pts_to | val pts_to (#n:US.t) (bv:bv_t n) (p:perm) (s:repr) : vprop | val pts_to (#n:US.t) (bv:bv_t n) (p:perm) (s:repr) : vprop | let pts_to bv p s = A.pts_to bv p s | {
"file_name": "lib/steel/Steel.ST.BitVector.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 35,
"end_line": 33,
"start_col": 0,
"start_line": 33
} | (*
Copyright 2021 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.
Authors: Aseem Rastogi
*)
module Steel.ST.BitVector
open Steel.ST.Effect.Ghost
open Steel.ST.Effect
open Steel.ST.Util
module US = FStar.SizeT
module G = FStar.Ghost
module A = Steel.ST.Array
/// Implementation of bv_t using an array of bool
type bv_t n = a:A.array bool{A.length a == US.v n /\ A.is_full_array a} | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Effect.Ghost.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.BitVector.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | bv: Steel.ST.BitVector.bv_t n -> p: Steel.FractionalPermission.perm -> s: Steel.ST.BitVector.repr
-> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Steel.ST.BitVector.bv_t",
"Steel.FractionalPermission.perm",
"Steel.ST.BitVector.repr",
"Steel.ST.Array.pts_to",
"Prims.bool",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | false | false | let pts_to bv p s =
| A.pts_to bv p s | false |
Hacl.Impl.RSAPSS.Padding.fst | Hacl.Impl.RSAPSS.Padding.db_zero | val db_zero:
len:size_t{v len > 0}
-> db:lbuffer uint8 len
-> emBits:size_t ->
Stack unit
(requires fun h -> live h db)
(ensures fun h0 _ h1 -> modifies (loc db) h0 h1 /\
as_seq h1 db == S.db_zero #(v len) (as_seq h0 db) (v emBits)) | val db_zero:
len:size_t{v len > 0}
-> db:lbuffer uint8 len
-> emBits:size_t ->
Stack unit
(requires fun h -> live h db)
(ensures fun h0 _ h1 -> modifies (loc db) h0 h1 /\
as_seq h1 db == S.db_zero #(v len) (as_seq h0 db) (v emBits)) | let db_zero len db emBits =
let msBits = emBits %. 8ul in
if msBits >. 0ul then
db.(0ul) <- db.(0ul) &. (u8 0xff >>. (8ul -. msBits)) | {
"file_name": "code/rsapss/Hacl.Impl.RSAPSS.Padding.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 65,
"start_col": 0,
"start_line": 62
} | module Hacl.Impl.RSAPSS.Padding
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.RSAPSS.MGF
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Hash = Spec.Agile.Hash
module S = Spec.RSAPSS
module BD = Hacl.Bignum.Definitions
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let less_than_max_input_length = Spec.Hash.Definitions.less_than_max_input_length
inline_for_extraction noextract
let salt_len_t (a:Hash.fixed_len_alg) =
saltLen:size_t{8 + Hash.hash_length a + v saltLen <= max_size_t /\ (8 + Hash.hash_length a + v saltLen) `less_than_max_input_length` a}
inline_for_extraction noextract
let msg_len_t (a:Hash.fixed_len_alg) =
msgLen:size_t{v msgLen `less_than_max_input_length` a}
inline_for_extraction noextract
let em_len_t (a:Hash.fixed_len_alg) (saltLen:salt_len_t a) =
emBits:size_t{0 < v emBits /\ Hash.hash_length a + v saltLen + 2 <= S.blocks (v emBits) 8}
inline_for_extraction noextract
val xor_bytes:
len:size_t{v len > 0}
-> b1:lbuffer uint8 len
-> b2:lbuffer uint8 len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1) h0 h1 /\
as_seq h1 b1 == S.xor_bytes (as_seq h0 b1) (as_seq h0 b2))
let xor_bytes len b1 b2 =
map2T len b1 (fun x y -> x ^. y) b1 b2
inline_for_extraction noextract
val db_zero:
len:size_t{v len > 0}
-> db:lbuffer uint8 len
-> emBits:size_t ->
Stack unit
(requires fun h -> live h db)
(ensures fun h0 _ h1 -> modifies (loc db) h0 h1 /\
as_seq h1 db == S.db_zero #(v len) (as_seq h0 db) (v emBits)) | {
"checked_file": "/",
"dependencies": [
"Spec.RSAPSS.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.RSAPSS.MGF.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.RSAPSS.Padding.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Spec.RSAPSS",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS.MGF",
"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.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
db: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len ->
emBits: Lib.IntTypes.size_t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.op_Greater_Dot",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.op_Array_Assignment",
"Prims.unit",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.op_Greater_Greater_Dot",
"Lib.IntTypes.u8",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"Prims.bool",
"Lib.IntTypes.op_Percent_Dot"
] | [] | false | true | false | false | false | let db_zero len db emBits =
| let msBits = emBits %. 8ul in
if msBits >. 0ul then db.(0ul) <- db.(0ul) &. (u8 0xff >>. (8ul -. msBits)) | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.next_addr | val next_addr: heap -> GTot pos | val next_addr: heap -> GTot pos | let next_addr h = h.next_addr | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 43,
"start_col": 0,
"start_line": 43
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.Heap.heap -> Prims.GTot Prims.pos | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__next_addr",
"Prims.pos"
] | [] | false | false | false | false | false | let next_addr h =
| h.next_addr | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.is_mm | val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool | val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool | let is_mm #a #rel r = r.mm | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 54,
"start_col": 0,
"start_line": 54
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Monotonic.Heap.mref a rel -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__mm",
"Prims.bool"
] | [] | false | false | false | false | false | let is_mm #a #rel r =
| r.mm | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.heap | val heap :Type u#1 | val heap :Type u#1 | let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))} | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 80,
"end_line": 29,
"start_col": 0,
"start_line": 29
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.Heap.heap_rec",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__next_addr",
"FStar.Pervasives.Native.uu___is_None",
"FStar.Pervasives.dtuple4",
"FStar.Pervasives.Native.option",
"FStar.Preorder.preorder",
"Prims.bool",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory"
] | [] | false | false | false | true | true | let heap =
| h: heap_rec{(forall (n: nat). n >= h.next_addr ==> None? (h.memory n))} | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.equal | val equal: heap -> heap -> Type0 | val equal: heap -> heap -> Type0 | let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 34,
"start_col": 0,
"start_line": 31
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h1: FStar.Monotonic.Heap.heap -> h2: FStar.Monotonic.Heap.heap -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.Heap.heap",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.pos",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__next_addr",
"FStar.FunctionalExtensionality.feq",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.dtuple4",
"FStar.Preorder.preorder",
"Prims.bool",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory",
"Prims.unit"
] | [] | false | false | false | true | true | let equal h1 h2 =
| let _ = () in
h1.next_addr = h2.next_addr /\ FStar.FunctionalExtensionality.feq h1.memory h2.memory | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.emp | val emp :heap | val emp :heap | let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
} | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 41,
"start_col": 0,
"start_line": 38
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Monotonic.Heap.heap | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.Heap.Mkheap_rec",
"FStar.FunctionalExtensionality.on_dom",
"Prims.pos",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.dtuple4",
"FStar.Preorder.preorder",
"Prims.bool",
"FStar.Pervasives.Native.None"
] | [] | false | false | false | true | false | let emp =
| { next_addr = 1; memory = F.on_dom pos (fun r -> None) } | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.addr_of | val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos | val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos | let addr_of #a #rel r = r.addr | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 52,
"start_col": 0,
"start_line": 52
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Monotonic.Heap.mref a rel -> Prims.GTot Prims.pos | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__addr",
"Prims.pos"
] | [] | false | false | false | false | false | let addr_of #a #rel r =
| r.addr | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.unused_in | val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0 | val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0 | let unused_in #a #rel r h = addr_unused_in (addr_of r) h | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 66,
"start_col": 0,
"start_line": 66
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Monotonic.Heap.mref a rel -> h: FStar.Monotonic.Heap.heap -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.addr_unused_in",
"FStar.Monotonic.Heap.addr_of"
] | [] | false | false | false | false | true | let unused_in #a #rel r h =
| addr_unused_in (addr_of r) h | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.addr_unused_in | val addr_unused_in: nat -> heap -> Type0 | val addr_unused_in: nat -> heap -> Type0 | let addr_unused_in n h = n <> 0 && None? (h.memory n) | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 62,
"start_col": 0,
"start_line": 62
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why? | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> h: FStar.Monotonic.Heap.heap -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Monotonic.Heap.heap",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_disEquality",
"Prims.int",
"FStar.Pervasives.Native.uu___is_None",
"FStar.Pervasives.dtuple4",
"FStar.Pervasives.Native.option",
"FStar.Preorder.preorder",
"Prims.bool",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory"
] | [] | false | false | false | true | true | let addr_unused_in n h =
| n <> 0 && None? (h.memory n) | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.contains | val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0 | val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0 | let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 67,
"end_line": 60,
"start_col": 0,
"start_line": 56
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.Heap.heap -> r: FStar.Monotonic.Heap.mref a rel -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.dtuple4",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__addr",
"Prims.eq2",
"FStar.Preorder.relation",
"Prims.l_or",
"FStar.Preorder.preorder_rel",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Prims.op_Equality",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__mm",
"Prims.logical",
"Prims.unit"
] | [] | false | false | false | false | true | let contains #a #rel h r =
| let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1 , pre_opt , mm , _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.sel | val sel: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> GTot a | val sel: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> GTot a | let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 91,
"start_col": 0,
"start_line": 88
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)}) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.Heap.heap -> r: FStar.Monotonic.Heap.mref a rel -> Prims.GTot a | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.contains_bool",
"FStar.Monotonic.Heap.sel_tot",
"Prims.bool",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__init"
] | [] | false | false | false | false | false | let sel #a #rel h r =
| if h `contains_bool` r then sel_tot #a h r else r.init | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.upd_tot' | val upd_tot' : h: FStar.Monotonic.Heap.heap -> r: FStar.Monotonic.Heap.mref a rel -> x: a
-> FStar.Monotonic.Heap.heap_rec | let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') } | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 96,
"start_col": 0,
"start_line": 93
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.Heap.heap -> r: FStar.Monotonic.Heap.mref a rel -> x: a
-> FStar.Monotonic.Heap.heap_rec | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.Mkheap_rec",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__next_addr",
"FStar.FunctionalExtensionality.on_dom",
"Prims.pos",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.dtuple4",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__addr",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Mkdtuple4",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__mm",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory",
"FStar.Monotonic.Heap.heap_rec"
] | [] | false | false | false | false | false | let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
| {
h with
memory
=
F.on_dom pos (fun r' -> if r.addr = r' then Some (| a, Some rel, r.mm, x |) else h.memory r')
} | false |
|
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.sel_tot | val sel_tot: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r} -> Tot a | val sel_tot: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r} -> Tot a | let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 70,
"start_col": 0,
"start_line": 68
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.Heap.heap ->
r: FStar.Monotonic.Heap.mref a rel {FStar.Monotonic.Heap.contains h r}
-> a | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.contains",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Pervasives.dtuple4",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__addr"
] | [] | false | false | false | false | false | let sel_tot #a #rel h r =
| let Some (| _ , _ , _ , x |) = h.memory r.addr in
x | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.upd_tot | val upd_tot: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r} -> x:a -> Tot heap | val upd_tot: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r} -> x:a -> Tot heap | let upd_tot #a #rel h r x = upd_tot' h r x | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 98,
"start_col": 0,
"start_line": 98
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.Heap.heap ->
r: FStar.Monotonic.Heap.mref a rel {FStar.Monotonic.Heap.contains h r} ->
x: a
-> FStar.Monotonic.Heap.heap | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.contains",
"FStar.Monotonic.Heap.upd_tot'"
] | [] | false | false | false | false | false | let upd_tot #a #rel h r x =
| upd_tot' h r x | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.free_mm | val free_mm: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r /\ is_mm r} -> Tot heap | val free_mm: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r /\ is_mm r} -> Tot heap | let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') } | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 88,
"end_line": 123,
"start_col": 0,
"start_line": 122
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.Heap.heap ->
r:
FStar.Monotonic.Heap.mref a rel
{FStar.Monotonic.Heap.contains h r /\ FStar.Monotonic.Heap.is_mm r}
-> FStar.Monotonic.Heap.heap | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"Prims.l_and",
"FStar.Monotonic.Heap.contains",
"Prims.b2t",
"FStar.Monotonic.Heap.is_mm",
"FStar.Monotonic.Heap.Mkheap_rec",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__next_addr",
"FStar.FunctionalExtensionality.on_dom",
"Prims.pos",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.dtuple4",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThan",
"Prims.op_GreaterThanOrEqual",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__addr",
"FStar.Pervasives.Native.None",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory"
] | [] | false | false | false | false | false | let free_mm #a #rel h r =
| { h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') } | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.upd | val upd: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel -> x:a -> GTot heap | val upd: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel -> x:a -> GTot heap | let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') } | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 64,
"end_line": 113,
"start_col": 0,
"start_line": 100
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.Heap.heap -> r: FStar.Monotonic.Heap.mref a rel -> x: a
-> Prims.GTot FStar.Monotonic.Heap.heap | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.contains_bool",
"FStar.Monotonic.Heap.upd_tot'",
"Prims.bool",
"Prims.op_GreaterThanOrEqual",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__addr",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__next_addr",
"FStar.Monotonic.Heap.Mkheap_rec",
"Prims.op_Addition",
"FStar.FunctionalExtensionality.on_dom",
"Prims.pos",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.dtuple4",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.l_and",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Mkdtuple4",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__mm",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory"
] | [] | false | false | false | false | false | let upd #a #rel h r x =
| if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{
next_addr = r.addr + 1;
memory
=
F.on_dom pos (fun r' -> if r' = r.addr then Some (| a, Some rel, r.mm, x |) else h.memory r')
}
else
{
h with
memory
=
F.on_dom pos (fun r' -> if r' = r.addr then Some (| a, Some rel, r.mm, x |) else h.memory r')
} | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.alloc | val alloc: #a:Type0 -> rel:preorder a -> heap -> a -> mm:bool -> Tot (mref a rel * heap) | val alloc: #a:Type0 -> rel:preorder a -> heap -> a -> mm:bool -> Tot (mref a rel * heap) | let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') } | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 120,
"start_col": 0,
"start_line": 115
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | rel: FStar.Preorder.preorder a -> h: FStar.Monotonic.Heap.heap -> x: a -> mm: Prims.bool
-> FStar.Monotonic.Heap.mref a rel * FStar.Monotonic.Heap.heap | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"Prims.bool",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.Mkheap_rec",
"Prims.op_Addition",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__addr",
"FStar.FunctionalExtensionality.on_dom",
"Prims.pos",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.dtuple4",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Mkdtuple4",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__mm",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory",
"FStar.Monotonic.Heap.core_mref",
"FStar.Monotonic.Heap.Mkcore_mref",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__next_addr",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let alloc #a rel h x mm =
| let r = { addr = h.next_addr; init = x; mm = mm } in
r,
{
next_addr = r.addr + 1;
memory
=
F.on_dom pos (fun r' -> if r' = r.addr then Some (| a, Some rel, r.mm, x |) else h.memory r')
} | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.lemma_alloc | val lemma_alloc (#a:Type0) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (requires True)
(ensures (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ h1 == upd h0 r x /\ is_mm r = mm /\ addr_of r == next_addr h0))
[SMTPat (alloc rel h0 x mm)] | val lemma_alloc (#a:Type0) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (requires True)
(ensures (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ h1 == upd h0 r x /\ is_mm r = mm /\ addr_of r == next_addr h0))
[SMTPat (alloc rel h0 x mm)] | let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1') | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 204,
"start_col": 0,
"start_line": 201
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | rel: FStar.Preorder.preorder a -> h0: FStar.Monotonic.Heap.heap -> x: a -> mm: Prims.bool
-> FStar.Pervasives.Lemma
(ensures
(let _ = FStar.Monotonic.Heap.alloc rel h0 x mm in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ r h1 = _ in
FStar.Monotonic.Heap.fresh r h0 h1 /\ h1 == FStar.Monotonic.Heap.upd h0 r x /\
FStar.Monotonic.Heap.is_mm r = mm /\
FStar.Monotonic.Heap.addr_of r == FStar.Monotonic.Heap.next_addr h0)
<:
Type0)) [SMTPat (FStar.Monotonic.Heap.alloc rel h0 x mm)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"Prims.bool",
"FStar.Monotonic.Heap.mref",
"Prims._assert",
"FStar.Monotonic.Heap.equal",
"FStar.Monotonic.Heap.upd",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.Monotonic.Heap.alloc"
] | [] | false | false | true | false | false | let lemma_alloc #a rel h0 x mm =
| let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1') | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.aref_of | val aref_of: #t: Type0 -> #rel: preorder t -> r: mref t rel -> Tot aref | val aref_of: #t: Type0 -> #rel: preorder t -> r: mref t rel -> Tot aref | let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
} | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 268,
"start_col": 0,
"start_line": 265
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Monotonic.Heap.mref t rel -> FStar.Monotonic.Heap.aref | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.Mkaref'",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__addr",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__mm",
"FStar.Monotonic.Heap.aref"
] | [] | false | false | false | false | false | let aref_of #t #rel r =
| { a_addr = r.addr; a_mm = r.mm } | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.dummy_aref | val dummy_aref: aref | val dummy_aref: aref | let dummy_aref = {
a_addr = 1;
a_mm = false;
} | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 261,
"start_col": 0,
"start_line": 258
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Monotonic.Heap.aref | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.Heap.Mkaref'"
] | [] | false | false | false | true | false | let dummy_aref =
| { a_addr = 1; a_mm = false } | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.aref | val aref: Type0 | val aref: Type0 | let aref = aref' | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 16,
"end_line": 257,
"start_col": 0,
"start_line": 257
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.Heap.aref'"
] | [] | false | false | false | true | true | let aref =
| aref' | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.addr_of_aref | val addr_of_aref: a: aref -> GTot (n: nat { n > 0 } ) | val addr_of_aref: a: aref -> GTot (n: nat { n > 0 } ) | let addr_of_aref a = a.a_addr | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 271,
"start_col": 0,
"start_line": 271
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.Monotonic.Heap.aref -> Prims.GTot (n: Prims.nat{n > 0}) | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.Heap.aref",
"FStar.Monotonic.Heap.__proj__Mkaref'__item__a_addr",
"Prims.nat",
"Prims.b2t",
"Prims.op_GreaterThan"
] | [] | false | false | false | false | false | let addr_of_aref a =
| a.a_addr | false |
Steel.PCMMap.fst | Steel.PCMMap.map | val map : k: Prims.eqtype -> v: Type -> Type | let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
} | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 34,
"start_col": 0,
"start_line": 31
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k: Prims.eqtype -> v: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.Map.t",
"FStar.Set.equal",
"FStar.Map.domain",
"FStar.Set.complement",
"FStar.Set.empty"
] | [] | false | false | false | true | true | let map (k: eqtype) (v: Type) =
| m: Map.t k v {(Map.domain m) `Set.equal` (Set.complement Set.empty)} | false |
|
Steel.PCMMap.fst | Steel.PCMMap.composable_maps | val composable_maps (#a: _) (#k: eqtype) (p: pcm a) (m0 m1: map k a) : prop | val composable_maps (#a: _) (#k: eqtype) (p: pcm a) (m0 m1: map k a) : prop | let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 54,
"end_line": 42,
"start_col": 0,
"start_line": 37
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.PCM.pcm a -> m0: Steel.PCMMap.map k a -> m1: Steel.PCMMap.map k a -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"Steel.PCMMap.map",
"Prims.l_Forall",
"FStar.PCM.composable",
"FStar.Map.sel",
"Prims.prop"
] | [] | false | false | false | false | true | let composable_maps (#a: _) (#k: eqtype) (p: pcm a) (m0 m1: map k a) : prop =
| forall k. composable p (Map.sel m0 k) (Map.sel m1 k) | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.aref_is_mm | val aref_is_mm: aref -> GTot bool | val aref_is_mm: aref -> GTot bool | let aref_is_mm a = a.a_mm | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 25,
"end_line": 273,
"start_col": 0,
"start_line": 273
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
}
(* Operators lifted from ref *)
let addr_of_aref a = a.a_addr | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.Monotonic.Heap.aref -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.Heap.aref",
"FStar.Monotonic.Heap.__proj__Mkaref'__item__a_mm",
"Prims.bool"
] | [] | false | false | false | false | false | let aref_is_mm a =
| a.a_mm | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.lemma_heap_equality_upd_with_sel | val lemma_heap_equality_upd_with_sel
(#a:Type) (#rel:preorder a) (h:heap) (r:mref a rel)
:Lemma (requires (h `contains` r))
(ensures (upd h r (sel h r) == h)) | val lemma_heap_equality_upd_with_sel
(#a:Type) (#rel:preorder a) (h:heap) (r:mref a rel)
:Lemma (requires (h `contains` r))
(ensures (upd h r (sel h r) == h)) | let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h') | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 237,
"start_col": 0,
"start_line": 234
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.Heap.heap -> r: FStar.Monotonic.Heap.mref a rel
-> FStar.Pervasives.Lemma (requires FStar.Monotonic.Heap.contains h r)
(ensures FStar.Monotonic.Heap.upd h r (FStar.Monotonic.Heap.sel h r) == h) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Prims._assert",
"FStar.Monotonic.Heap.equal",
"Prims.unit",
"FStar.Pervasives.dtuple4",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory",
"FStar.Monotonic.Heap.__proj__Mkcore_mref__item__addr",
"FStar.Monotonic.Heap.upd",
"FStar.Monotonic.Heap.sel"
] | [] | false | false | true | false | false | let lemma_heap_equality_upd_with_sel #a #rel h r =
| let h' = upd h r (sel h r) in
let Some (| _ , _ , _ , _ |) = h.memory r.addr in
assert (equal h h') | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.lemma_heap_equality_upd_same_addr | val lemma_heap_equality_upd_same_addr (#a: Type0) (#rel: preorder a) (h: heap) (r1 r2: mref a rel) (x: a)
:Lemma (requires ((h `contains` r1 \/ h `contains` r2) /\ addr_of r1 = addr_of r2 /\ is_mm r1 == is_mm r2))
(ensures (upd h r1 x == upd h r2 x)) | val lemma_heap_equality_upd_same_addr (#a: Type0) (#rel: preorder a) (h: heap) (r1 r2: mref a rel) (x: a)
:Lemma (requires ((h `contains` r1 \/ h `contains` r2) /\ addr_of r1 = addr_of r2 /\ is_mm r1 == is_mm r2))
(ensures (upd h r1 x == upd h r2 x)) | let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x)) | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 227,
"start_col": 0,
"start_line": 226
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.Heap.heap ->
r1: FStar.Monotonic.Heap.mref a rel ->
r2: FStar.Monotonic.Heap.mref a rel ->
x: a
-> FStar.Pervasives.Lemma
(requires
(FStar.Monotonic.Heap.contains h r1 \/ FStar.Monotonic.Heap.contains h r2) /\
FStar.Monotonic.Heap.addr_of r1 = FStar.Monotonic.Heap.addr_of r2 /\
FStar.Monotonic.Heap.is_mm r1 == FStar.Monotonic.Heap.is_mm r2)
(ensures FStar.Monotonic.Heap.upd h r1 x == FStar.Monotonic.Heap.upd h r2 x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"Prims._assert",
"FStar.Monotonic.Heap.equal",
"FStar.Monotonic.Heap.upd",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
| assert (equal (upd h r1 x) (upd h r2 x)) | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.lemma_heap_equality_cancel_same_mref_upd | val lemma_heap_equality_cancel_same_mref_upd
(#a:Type) (#rel:preorder a) (h:heap) (r:mref a rel)
(x:a) (y:a)
:Lemma (requires True)
(ensures (upd (upd h r x) r y == upd h r y)) | val lemma_heap_equality_cancel_same_mref_upd
(#a:Type) (#rel:preorder a) (h:heap) (r:mref a rel)
(x:a) (y:a)
:Lemma (requires True)
(ensures (upd (upd h r x) r y == upd h r y)) | let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1) | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 232,
"start_col": 0,
"start_line": 229
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.Heap.heap -> r: FStar.Monotonic.Heap.mref a rel -> x: a -> y: a
-> FStar.Pervasives.Lemma
(ensures
FStar.Monotonic.Heap.upd (FStar.Monotonic.Heap.upd h r x) r y ==
FStar.Monotonic.Heap.upd h r y) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"Prims._assert",
"FStar.Monotonic.Heap.equal",
"FStar.Monotonic.Heap.upd",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
| let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1) | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.lemma_heap_equality_commute_distinct_upds | val lemma_heap_equality_commute_distinct_upds
(#a:Type) (#b:Type) (#rel_a:preorder a) (#rel_b:preorder b) (h:heap) (r1:mref a rel_a) (r2:mref b rel_b)
(x:a) (y:b)
:Lemma (requires (addr_of r1 =!= addr_of r2))
(ensures (upd (upd h r1 x) r2 y == upd (upd h r2 y) r1 x)) | val lemma_heap_equality_commute_distinct_upds
(#a:Type) (#b:Type) (#rel_a:preorder a) (#rel_b:preorder b) (h:heap) (r1:mref a rel_a) (r2:mref b rel_b)
(x:a) (y:b)
:Lemma (requires (addr_of r1 =!= addr_of r2))
(ensures (upd (upd h r1 x) r2 y == upd (upd h r2 y) r1 x)) | let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1) | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 242,
"start_col": 0,
"start_line": 239
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.Heap.heap ->
r1: FStar.Monotonic.Heap.mref a rel_a ->
r2: FStar.Monotonic.Heap.mref b rel_b ->
x: a ->
y: b
-> FStar.Pervasives.Lemma
(requires ~(FStar.Monotonic.Heap.addr_of r1 == FStar.Monotonic.Heap.addr_of r2))
(ensures
FStar.Monotonic.Heap.upd (FStar.Monotonic.Heap.upd h r1 x) r2 y ==
FStar.Monotonic.Heap.upd (FStar.Monotonic.Heap.upd h r2 y) r1 x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.mref",
"Prims._assert",
"FStar.Monotonic.Heap.equal",
"FStar.Monotonic.Heap.upd",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
| let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1) | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.ref_of | val ref_of: h: heap -> a: aref -> t: Type0 -> rel: preorder t -> Pure (mref t rel) (requires (aref_live_at h a t rel)) (ensures (fun x -> aref_live_at h a t rel /\ addr_of (gref_of a t rel) == addr_of x /\ is_mm x == aref_is_mm a)) | val ref_of: h: heap -> a: aref -> t: Type0 -> rel: preorder t -> Pure (mref t rel) (requires (aref_live_at h a t rel)) (ensures (fun x -> aref_live_at h a t rel /\ addr_of (gref_of a t rel) == addr_of x /\ is_mm x == aref_is_mm a)) | let ref_of h a t rel = ref_of' h a t rel | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 316,
"start_col": 0,
"start_line": 316
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
}
(* Operators lifted from ref *)
let addr_of_aref a = a.a_addr
let addr_of_aref_of #t #rel r = ()
let aref_is_mm a = a.a_mm
let is_mm_aref_of #t #rel r = ()
let aref_unused_in a h = None? (h.memory a.a_addr)
let unused_in_aref_of #t #rel r h = ()
let contains_aref_unused_in #a #rel h x y = ()
(* Elimination rule *)
let aref_live_at (h: heap) (a: aref) (t: Type0) (rel: preorder t) =
let _ = () in
Some? (h.memory a.a_addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory a.a_addr in
t == a1 /\ Some? pre_opt /\ Some?.v pre_opt === rel /\ mm == a.a_mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let ref_of'
(h: heap)
(a: aref)
(t: Type0)
(rel: preorder t)
: Pure (mref t rel)
(requires (aref_live_at h a t rel))
(ensures (fun _ -> True))
= let Some (| _, pre_opt, _, x |) = h.memory a.a_addr in
{
addr = a.a_addr;
init = x;
mm = a.a_mm
}
let gref_of a t rel =
let m : squash (exists (h: heap) . aref_live_at h a t rel) = () in
let l : (exists (h: heap) . aref_live_at h a t rel) =
Squash.join_squash #(h: heap & aref_live_at h a t rel) m
in
let k : (exists (h: heap { aref_live_at h a t rel} ) . squash True ) =
FStar.Squash.bind_squash
#(h: heap & aref_live_at h a t rel)
#(h: (h: heap { aref_live_at h a t rel} ) & squash True)
l
(fun h -> let (| h', _ |) = h in Squash.return_squash (| h', () |) )
in
let h = FStar.ErasedLogic.exists_proj1 #(h: heap {aref_live_at h a t rel}) #(fun _ -> squash True) k in
ref_of' h a t rel | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.Heap.heap ->
a: FStar.Monotonic.Heap.aref ->
t: Type0 ->
rel: FStar.Preorder.preorder t
-> Prims.Pure (FStar.Monotonic.Heap.mref t rel) | Prims.Pure | [] | [] | [
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.aref",
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.ref_of'",
"FStar.Monotonic.Heap.mref"
] | [] | false | false | false | false | false | let ref_of h a t rel =
| ref_of' h a t rel | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.aref_unused_in | val aref_unused_in: aref -> heap -> Type0 | val aref_unused_in: aref -> heap -> Type0 | let aref_unused_in a h = None? (h.memory a.a_addr) | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 275,
"start_col": 0,
"start_line": 275
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
}
(* Operators lifted from ref *)
let addr_of_aref a = a.a_addr
let addr_of_aref_of #t #rel r = ()
let aref_is_mm a = a.a_mm | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.Monotonic.Heap.aref -> h: FStar.Monotonic.Heap.heap -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.Heap.aref",
"FStar.Monotonic.Heap.heap",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_None",
"FStar.Pervasives.dtuple4",
"FStar.Pervasives.Native.option",
"FStar.Preorder.preorder",
"Prims.bool",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory",
"FStar.Monotonic.Heap.__proj__Mkaref'__item__a_addr"
] | [] | false | false | false | true | true | let aref_unused_in a h =
| None? (h.memory a.a_addr) | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.addr_of_gref_of | val addr_of_gref_of
(a: aref)
(t: Type0)
(rel: preorder t)
: Lemma
(requires (exists h . aref_live_at h a t rel))
(ensures ((exists h . aref_live_at h a t rel) /\ addr_of (gref_of a t rel) == addr_of_aref a))
[SMTPat (addr_of (gref_of a t rel))] | val addr_of_gref_of
(a: aref)
(t: Type0)
(rel: preorder t)
: Lemma
(requires (exists h . aref_live_at h a t rel))
(ensures ((exists h . aref_live_at h a t rel) /\ addr_of (gref_of a t rel) == addr_of_aref a))
[SMTPat (addr_of (gref_of a t rel))] | let addr_of_gref_of a t rel = addr_of_aref_of (gref_of a t rel) | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 322,
"start_col": 0,
"start_line": 322
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
}
(* Operators lifted from ref *)
let addr_of_aref a = a.a_addr
let addr_of_aref_of #t #rel r = ()
let aref_is_mm a = a.a_mm
let is_mm_aref_of #t #rel r = ()
let aref_unused_in a h = None? (h.memory a.a_addr)
let unused_in_aref_of #t #rel r h = ()
let contains_aref_unused_in #a #rel h x y = ()
(* Elimination rule *)
let aref_live_at (h: heap) (a: aref) (t: Type0) (rel: preorder t) =
let _ = () in
Some? (h.memory a.a_addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory a.a_addr in
t == a1 /\ Some? pre_opt /\ Some?.v pre_opt === rel /\ mm == a.a_mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let ref_of'
(h: heap)
(a: aref)
(t: Type0)
(rel: preorder t)
: Pure (mref t rel)
(requires (aref_live_at h a t rel))
(ensures (fun _ -> True))
= let Some (| _, pre_opt, _, x |) = h.memory a.a_addr in
{
addr = a.a_addr;
init = x;
mm = a.a_mm
}
let gref_of a t rel =
let m : squash (exists (h: heap) . aref_live_at h a t rel) = () in
let l : (exists (h: heap) . aref_live_at h a t rel) =
Squash.join_squash #(h: heap & aref_live_at h a t rel) m
in
let k : (exists (h: heap { aref_live_at h a t rel} ) . squash True ) =
FStar.Squash.bind_squash
#(h: heap & aref_live_at h a t rel)
#(h: (h: heap { aref_live_at h a t rel} ) & squash True)
l
(fun h -> let (| h', _ |) = h in Squash.return_squash (| h', () |) )
in
let h = FStar.ErasedLogic.exists_proj1 #(h: heap {aref_live_at h a t rel}) #(fun _ -> squash True) k in
ref_of' h a t rel
let ref_of h a t rel = ref_of' h a t rel
let aref_live_at_aref_of h #t #rel r = ()
let contains_gref_of h a t rel = ()
let aref_of_gref_of a t rel = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.Monotonic.Heap.aref -> t: Type0 -> rel: FStar.Preorder.preorder t
-> FStar.Pervasives.Lemma
(requires exists (h: FStar.Monotonic.Heap.heap). FStar.Monotonic.Heap.aref_live_at h a t rel)
(ensures
(exists (h: FStar.Monotonic.Heap.heap). FStar.Monotonic.Heap.aref_live_at h a t rel) /\
FStar.Monotonic.Heap.addr_of (FStar.Monotonic.Heap.gref_of a t rel) ==
FStar.Monotonic.Heap.addr_of_aref a)
[SMTPat (FStar.Monotonic.Heap.addr_of (FStar.Monotonic.Heap.gref_of a t rel))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Monotonic.Heap.aref",
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.addr_of_aref_of",
"FStar.Monotonic.Heap.gref_of",
"Prims.unit"
] | [] | true | false | true | false | false | let addr_of_gref_of a t rel =
| addr_of_aref_of (gref_of a t rel) | false |
Steel.PCMMap.fst | Steel.PCMMap.compose_maps | val compose_maps
(#a: _)
(#k: eqtype)
(p: pcm a)
(m0: map k a)
(m1: map k a {composable_maps p m0 m1})
: map k a | val compose_maps
(#a: _)
(#k: eqtype)
(p: pcm a)
(m0: map k a)
(m1: map k a {composable_maps p m0 m1})
: map k a | let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k) | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 56,
"end_line": 51,
"start_col": 0,
"start_line": 45
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: FStar.PCM.pcm a ->
m0: Steel.PCMMap.map k a ->
m1: Steel.PCMMap.map k a {Steel.PCMMap.composable_maps p m0 m1}
-> Steel.PCMMap.map k a | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"Steel.PCMMap.map",
"Steel.PCMMap.composable_maps",
"FStar.Map.map_literal",
"FStar.PCM.op",
"FStar.Map.sel"
] | [] | false | false | false | false | false | let compose_maps
(#a: _)
(#k: eqtype)
(p: pcm a)
(m0: map k a)
(m1: map k a {composable_maps p m0 m1})
: map k a =
| Map.map_literal (fun k -> op p (Map.sel m0 k) (Map.sel m1 k)) | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.aref_equal | val aref_equal (a1 a2: aref) : Ghost bool (requires True) (ensures (fun b -> b == true <==> a1 == a2)) | val aref_equal (a1 a2: aref) : Ghost bool (requires True) (ensures (fun b -> b == true <==> a1 == a2)) | let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 262,
"start_col": 0,
"start_line": 262
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a1: FStar.Monotonic.Heap.aref -> a2: FStar.Monotonic.Heap.aref -> Prims.Ghost Prims.bool | Prims.Ghost | [] | [] | [
"FStar.Monotonic.Heap.aref",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.nat",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Monotonic.Heap.__proj__Mkaref'__item__a_addr",
"Prims.bool",
"FStar.Monotonic.Heap.__proj__Mkaref'__item__a_mm"
] | [] | false | false | false | false | false | let aref_equal a1 a2 =
| a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.aref_live_at | val aref_live_at: h: heap -> a: aref -> t: Type0 -> rel: preorder t -> GTot Type0 | val aref_live_at: h: heap -> a: aref -> t: Type0 -> rel: preorder t -> GTot Type0 | let aref_live_at (h: heap) (a: aref) (t: Type0) (rel: preorder t) =
let _ = () in
Some? (h.memory a.a_addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory a.a_addr in
t == a1 /\ Some? pre_opt /\ Some?.v pre_opt === rel /\ mm == a.a_mm) | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 71,
"end_line": 284,
"start_col": 0,
"start_line": 280
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
}
(* Operators lifted from ref *)
let addr_of_aref a = a.a_addr
let addr_of_aref_of #t #rel r = ()
let aref_is_mm a = a.a_mm
let is_mm_aref_of #t #rel r = ()
let aref_unused_in a h = None? (h.memory a.a_addr)
let unused_in_aref_of #t #rel r h = ()
let contains_aref_unused_in #a #rel h x y = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.Heap.heap ->
a: FStar.Monotonic.Heap.aref ->
t: Type0 ->
rel: FStar.Preorder.preorder t
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.aref",
"FStar.Preorder.preorder",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.dtuple4",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory",
"FStar.Monotonic.Heap.__proj__Mkaref'__item__a_addr",
"Prims.eq2",
"Prims.op_Equals_Equals_Equals",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.Monotonic.Heap.__proj__Mkaref'__item__a_mm",
"Prims.logical",
"Prims.unit"
] | [] | false | false | false | false | true | let aref_live_at (h: heap) (a: aref) (t: Type0) (rel: preorder t) =
| let _ = () in
Some? (h.memory a.a_addr) /\
(let Some (| a1 , pre_opt , mm , _ |) = h.memory a.a_addr in
t == a1 /\ Some? pre_opt /\ Some?.v pre_opt === rel /\ mm == a.a_mm) | false |
Steel.PCMMap.fst | Steel.PCMMap.compose_maps_comm | val compose_maps_comm (#k #a: _) (p: pcm a) (m0 m1: map k a)
: Lemma (requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0) | val compose_maps_comm (#k #a: _) (p: pcm a) (m0 m1: map k a)
: Lemma (requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0) | let compose_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma
(requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0)
= let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key.
Map.sel m01 key == Map.sel m10 key
with ( p.comm (Map.sel m0 key) (Map.sel m1 key) );
assert (Map.equal m01 m10) | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 73,
"start_col": 0,
"start_line": 62
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k
/// Compose maps pointwise
let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k)
/// Composability is commutative
let composable_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma (composable_maps p m0 m1 <==>
composable_maps p m1 m0)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.PCM.pcm a -> m0: Steel.PCMMap.map k a -> m1: Steel.PCMMap.map k a
-> FStar.Pervasives.Lemma (requires Steel.PCMMap.composable_maps p m0 m1)
(ensures Steel.PCMMap.compose_maps p m0 m1 == Steel.PCMMap.compose_maps p m1 m0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"Steel.PCMMap.map",
"Prims._assert",
"FStar.Map.equal",
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eq2",
"FStar.Map.sel",
"FStar.PCM.__proj__Mkpcm__item__comm",
"Prims.squash",
"Steel.PCMMap.compose_maps",
"Steel.PCMMap.composable_maps",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let compose_maps_comm #k #a (p: pcm a) (m0: map k a) (m1: map k a)
: Lemma (requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0) =
| let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key . Map.sel m01 key == Map.sel m10 key
with (p.comm (Map.sel m0 key) (Map.sel m1 key));
assert (Map.equal m01 m10) | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.gref_of | val gref_of: a: aref -> t: Type0 -> rel: preorder t -> Ghost (mref t rel) (requires (exists h . aref_live_at h a t rel)) (ensures (fun _ -> True)) | val gref_of: a: aref -> t: Type0 -> rel: preorder t -> Ghost (mref t rel) (requires (exists h . aref_live_at h a t rel)) (ensures (fun _ -> True)) | let gref_of a t rel =
let m : squash (exists (h: heap) . aref_live_at h a t rel) = () in
let l : (exists (h: heap) . aref_live_at h a t rel) =
Squash.join_squash #(h: heap & aref_live_at h a t rel) m
in
let k : (exists (h: heap { aref_live_at h a t rel} ) . squash True ) =
FStar.Squash.bind_squash
#(h: heap & aref_live_at h a t rel)
#(h: (h: heap { aref_live_at h a t rel} ) & squash True)
l
(fun h -> let (| h', _ |) = h in Squash.return_squash (| h', () |) )
in
let h = FStar.ErasedLogic.exists_proj1 #(h: heap {aref_live_at h a t rel}) #(fun _ -> squash True) k in
ref_of' h a t rel | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 314,
"start_col": 0,
"start_line": 301
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
}
(* Operators lifted from ref *)
let addr_of_aref a = a.a_addr
let addr_of_aref_of #t #rel r = ()
let aref_is_mm a = a.a_mm
let is_mm_aref_of #t #rel r = ()
let aref_unused_in a h = None? (h.memory a.a_addr)
let unused_in_aref_of #t #rel r h = ()
let contains_aref_unused_in #a #rel h x y = ()
(* Elimination rule *)
let aref_live_at (h: heap) (a: aref) (t: Type0) (rel: preorder t) =
let _ = () in
Some? (h.memory a.a_addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory a.a_addr in
t == a1 /\ Some? pre_opt /\ Some?.v pre_opt === rel /\ mm == a.a_mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let ref_of'
(h: heap)
(a: aref)
(t: Type0)
(rel: preorder t)
: Pure (mref t rel)
(requires (aref_live_at h a t rel))
(ensures (fun _ -> True))
= let Some (| _, pre_opt, _, x |) = h.memory a.a_addr in
{
addr = a.a_addr;
init = x;
mm = a.a_mm
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.Monotonic.Heap.aref -> t: Type0 -> rel: FStar.Preorder.preorder t
-> Prims.Ghost (FStar.Monotonic.Heap.mref t rel) | Prims.Ghost | [] | [] | [
"FStar.Monotonic.Heap.aref",
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.ref_of'",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.aref_live_at",
"FStar.ErasedLogic.exists_proj1",
"Prims.squash",
"Prims.l_True",
"Prims.l_Exists",
"FStar.Squash.bind_squash",
"Prims.dtuple2",
"FStar.Squash.return_squash",
"Prims.Mkdtuple2",
"FStar.Squash.join_squash",
"FStar.Monotonic.Heap.mref"
] | [] | false | false | false | false | false | let gref_of a t rel =
| let m:squash (exists (h: heap). aref_live_at h a t rel) = () in
let l:(exists (h: heap). aref_live_at h a t rel) =
Squash.join_squash #(h: heap & aref_live_at h a t rel) m
in
let k:(exists (h: heap{aref_live_at h a t rel}). squash True) =
FStar.Squash.bind_squash #(h: heap & aref_live_at h a t rel)
#(h: (h: heap{aref_live_at h a t rel}) & squash True)
l
(fun h ->
let (| h' , _ |) = h in
Squash.return_squash (| h', () |))
in
let h =
FStar.ErasedLogic.exists_proj1 #(h: heap{aref_live_at h a t rel}) #(fun _ -> squash True) k
in
ref_of' h a t rel | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.ref_of' | val ref_of' (h: heap) (a: aref) (t: Type0) (rel: preorder t)
: Pure (mref t rel) (requires (aref_live_at h a t rel)) (ensures (fun _ -> True)) | val ref_of' (h: heap) (a: aref) (t: Type0) (rel: preorder t)
: Pure (mref t rel) (requires (aref_live_at h a t rel)) (ensures (fun _ -> True)) | let ref_of'
(h: heap)
(a: aref)
(t: Type0)
(rel: preorder t)
: Pure (mref t rel)
(requires (aref_live_at h a t rel))
(ensures (fun _ -> True))
= let Some (| _, pre_opt, _, x |) = h.memory a.a_addr in
{
addr = a.a_addr;
init = x;
mm = a.a_mm
} | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 299,
"start_col": 0,
"start_line": 286
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
}
(* Operators lifted from ref *)
let addr_of_aref a = a.a_addr
let addr_of_aref_of #t #rel r = ()
let aref_is_mm a = a.a_mm
let is_mm_aref_of #t #rel r = ()
let aref_unused_in a h = None? (h.memory a.a_addr)
let unused_in_aref_of #t #rel r h = ()
let contains_aref_unused_in #a #rel h x y = ()
(* Elimination rule *)
let aref_live_at (h: heap) (a: aref) (t: Type0) (rel: preorder t) =
let _ = () in
Some? (h.memory a.a_addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory a.a_addr in
t == a1 /\ Some? pre_opt /\ Some?.v pre_opt === rel /\ mm == a.a_mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why? | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.Heap.heap ->
a: FStar.Monotonic.Heap.aref ->
t: Type0 ->
rel: FStar.Preorder.preorder t
-> Prims.Pure (FStar.Monotonic.Heap.mref t rel) | Prims.Pure | [] | [] | [
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.aref",
"FStar.Preorder.preorder",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Monotonic.Heap.Mkcore_mref",
"FStar.Monotonic.Heap.__proj__Mkaref'__item__a_addr",
"FStar.Monotonic.Heap.__proj__Mkaref'__item__a_mm",
"FStar.Monotonic.Heap.mref",
"FStar.Pervasives.dtuple4",
"FStar.Monotonic.Heap.__proj__Mkheap_rec__item__memory",
"FStar.Monotonic.Heap.aref_live_at",
"Prims.l_True"
] | [] | false | false | false | false | false | let ref_of' (h: heap) (a: aref) (t: Type0) (rel: preorder t)
: Pure (mref t rel) (requires (aref_live_at h a t rel)) (ensures (fun _ -> True)) =
| let Some (| _ , pre_opt , _ , x |) = h.memory a.a_addr in
{ addr = a.a_addr; init = x; mm = a.a_mm } | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.unused_in_gref_of | val unused_in_gref_of
(a: aref)
(t: Type0)
(rel: preorder t)
(h: heap)
: Lemma
(requires (exists h . aref_live_at h a t rel))
(ensures ((exists h . aref_live_at h a t rel) /\ (unused_in (gref_of a t rel) h <==> aref_unused_in a h)))
[SMTPat (unused_in (gref_of a t rel) h)] | val unused_in_gref_of
(a: aref)
(t: Type0)
(rel: preorder t)
(h: heap)
: Lemma
(requires (exists h . aref_live_at h a t rel))
(ensures ((exists h . aref_live_at h a t rel) /\ (unused_in (gref_of a t rel) h <==> aref_unused_in a h)))
[SMTPat (unused_in (gref_of a t rel) h)] | let unused_in_gref_of a t rel h = unused_in_aref_of (gref_of a t rel) h | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 71,
"end_line": 326,
"start_col": 0,
"start_line": 326
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
}
(* Operators lifted from ref *)
let addr_of_aref a = a.a_addr
let addr_of_aref_of #t #rel r = ()
let aref_is_mm a = a.a_mm
let is_mm_aref_of #t #rel r = ()
let aref_unused_in a h = None? (h.memory a.a_addr)
let unused_in_aref_of #t #rel r h = ()
let contains_aref_unused_in #a #rel h x y = ()
(* Elimination rule *)
let aref_live_at (h: heap) (a: aref) (t: Type0) (rel: preorder t) =
let _ = () in
Some? (h.memory a.a_addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory a.a_addr in
t == a1 /\ Some? pre_opt /\ Some?.v pre_opt === rel /\ mm == a.a_mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let ref_of'
(h: heap)
(a: aref)
(t: Type0)
(rel: preorder t)
: Pure (mref t rel)
(requires (aref_live_at h a t rel))
(ensures (fun _ -> True))
= let Some (| _, pre_opt, _, x |) = h.memory a.a_addr in
{
addr = a.a_addr;
init = x;
mm = a.a_mm
}
let gref_of a t rel =
let m : squash (exists (h: heap) . aref_live_at h a t rel) = () in
let l : (exists (h: heap) . aref_live_at h a t rel) =
Squash.join_squash #(h: heap & aref_live_at h a t rel) m
in
let k : (exists (h: heap { aref_live_at h a t rel} ) . squash True ) =
FStar.Squash.bind_squash
#(h: heap & aref_live_at h a t rel)
#(h: (h: heap { aref_live_at h a t rel} ) & squash True)
l
(fun h -> let (| h', _ |) = h in Squash.return_squash (| h', () |) )
in
let h = FStar.ErasedLogic.exists_proj1 #(h: heap {aref_live_at h a t rel}) #(fun _ -> squash True) k in
ref_of' h a t rel
let ref_of h a t rel = ref_of' h a t rel
let aref_live_at_aref_of h #t #rel r = ()
let contains_gref_of h a t rel = ()
let aref_of_gref_of a t rel = ()
let addr_of_gref_of a t rel = addr_of_aref_of (gref_of a t rel)
let is_mm_gref_of a t rel = is_mm_aref_of (gref_of a t rel) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: FStar.Monotonic.Heap.aref ->
t: Type0 ->
rel: FStar.Preorder.preorder t ->
h: FStar.Monotonic.Heap.heap
-> FStar.Pervasives.Lemma
(requires exists (h: FStar.Monotonic.Heap.heap). FStar.Monotonic.Heap.aref_live_at h a t rel)
(ensures
(exists (h: FStar.Monotonic.Heap.heap). FStar.Monotonic.Heap.aref_live_at h a t rel) /\
(FStar.Monotonic.Heap.unused_in (FStar.Monotonic.Heap.gref_of a t rel) h <==>
FStar.Monotonic.Heap.aref_unused_in a h))
[SMTPat (FStar.Monotonic.Heap.unused_in (FStar.Monotonic.Heap.gref_of a t rel) h)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Monotonic.Heap.aref",
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.unused_in_aref_of",
"FStar.Monotonic.Heap.gref_of",
"Prims.unit"
] | [] | true | false | true | false | false | let unused_in_gref_of a t rel h =
| unused_in_aref_of (gref_of a t rel) h | false |
Steel.PCMMap.fst | Steel.PCMMap.pcm'_map_of_pcm | val pcm'_map_of_pcm (#a: _) (k: eqtype) (p: pcm a) : pcm' (map k a) | val pcm'_map_of_pcm (#a: _) (k: eqtype) (p: pcm a) : pcm' (map k a) | let pcm'_map_of_pcm (#a:_) (k:eqtype) (p:pcm a)
: pcm' (map k a)
= {
composable = composable_maps p;
op = compose_maps p;
one = Map.const p.p.one
} | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 139,
"start_col": 0,
"start_line": 133
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k
/// Compose maps pointwise
let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k)
/// Composability is commutative
let composable_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma (composable_maps p m0 m1 <==>
composable_maps p m1 m0)
= ()
/// Composition is commutative
let compose_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma
(requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0)
= let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key.
Map.sel m01 key == Map.sel m10 key
with ( p.comm (Map.sel m0 key) (Map.sel m1 key) );
assert (Map.equal m01 m10)
/// Composability is left-associative
let composable_maps_assoc_l #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m0 key) (Map.sel m1 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m01 = compose_maps p m0 m1 in
introduce forall key.
composable p (Map.sel m01 key) (Map.sel m2 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p m01 m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal
(compose_maps p (compose_maps p m0 m1) m2)
(compose_maps p m0 (compose_maps p m1 m2)))
/// Composability is right-associative
let composable_maps_assoc_r #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m1 key) (Map.sel m2 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m12 = compose_maps p m1 m2 in
introduce forall key.
composable p (Map.sel m0 key) (Map.sel m12 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p (compose_maps p m0 m1) m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal m012 m012')
/// The core of the constructed PCM | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k: Prims.eqtype -> p: FStar.PCM.pcm a -> FStar.PCM.pcm' (Steel.PCMMap.map k a) | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"FStar.PCM.Mkpcm'",
"Steel.PCMMap.map",
"Steel.PCMMap.composable_maps",
"Steel.PCMMap.compose_maps",
"FStar.Map.const",
"FStar.PCM.__proj__Mkpcm'__item__one",
"FStar.PCM.__proj__Mkpcm__item__p",
"FStar.PCM.pcm'"
] | [] | false | false | false | false | false | let pcm'_map_of_pcm (#a: _) (k: eqtype) (p: pcm a) : pcm' (map k a) =
| { composable = composable_maps p; op = compose_maps p; one = Map.const p.p.one } | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.is_mm_gref_of | val is_mm_gref_of
(a: aref)
(t: Type0)
(rel: preorder t)
: Lemma
(requires (exists h . aref_live_at h a t rel))
(ensures ((exists h . aref_live_at h a t rel) /\ is_mm (gref_of a t rel) == aref_is_mm a))
[SMTPat (is_mm (gref_of a t rel))] | val is_mm_gref_of
(a: aref)
(t: Type0)
(rel: preorder t)
: Lemma
(requires (exists h . aref_live_at h a t rel))
(ensures ((exists h . aref_live_at h a t rel) /\ is_mm (gref_of a t rel) == aref_is_mm a))
[SMTPat (is_mm (gref_of a t rel))] | let is_mm_gref_of a t rel = is_mm_aref_of (gref_of a t rel) | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 324,
"start_col": 0,
"start_line": 324
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
}
(* Operators lifted from ref *)
let addr_of_aref a = a.a_addr
let addr_of_aref_of #t #rel r = ()
let aref_is_mm a = a.a_mm
let is_mm_aref_of #t #rel r = ()
let aref_unused_in a h = None? (h.memory a.a_addr)
let unused_in_aref_of #t #rel r h = ()
let contains_aref_unused_in #a #rel h x y = ()
(* Elimination rule *)
let aref_live_at (h: heap) (a: aref) (t: Type0) (rel: preorder t) =
let _ = () in
Some? (h.memory a.a_addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory a.a_addr in
t == a1 /\ Some? pre_opt /\ Some?.v pre_opt === rel /\ mm == a.a_mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let ref_of'
(h: heap)
(a: aref)
(t: Type0)
(rel: preorder t)
: Pure (mref t rel)
(requires (aref_live_at h a t rel))
(ensures (fun _ -> True))
= let Some (| _, pre_opt, _, x |) = h.memory a.a_addr in
{
addr = a.a_addr;
init = x;
mm = a.a_mm
}
let gref_of a t rel =
let m : squash (exists (h: heap) . aref_live_at h a t rel) = () in
let l : (exists (h: heap) . aref_live_at h a t rel) =
Squash.join_squash #(h: heap & aref_live_at h a t rel) m
in
let k : (exists (h: heap { aref_live_at h a t rel} ) . squash True ) =
FStar.Squash.bind_squash
#(h: heap & aref_live_at h a t rel)
#(h: (h: heap { aref_live_at h a t rel} ) & squash True)
l
(fun h -> let (| h', _ |) = h in Squash.return_squash (| h', () |) )
in
let h = FStar.ErasedLogic.exists_proj1 #(h: heap {aref_live_at h a t rel}) #(fun _ -> squash True) k in
ref_of' h a t rel
let ref_of h a t rel = ref_of' h a t rel
let aref_live_at_aref_of h #t #rel r = ()
let contains_gref_of h a t rel = ()
let aref_of_gref_of a t rel = ()
let addr_of_gref_of a t rel = addr_of_aref_of (gref_of a t rel) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.Monotonic.Heap.aref -> t: Type0 -> rel: FStar.Preorder.preorder t
-> FStar.Pervasives.Lemma
(requires exists (h: FStar.Monotonic.Heap.heap). FStar.Monotonic.Heap.aref_live_at h a t rel)
(ensures
(exists (h: FStar.Monotonic.Heap.heap). FStar.Monotonic.Heap.aref_live_at h a t rel) /\
FStar.Monotonic.Heap.is_mm (FStar.Monotonic.Heap.gref_of a t rel) ==
FStar.Monotonic.Heap.aref_is_mm a)
[SMTPat (FStar.Monotonic.Heap.is_mm (FStar.Monotonic.Heap.gref_of a t rel))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Monotonic.Heap.aref",
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.is_mm_aref_of",
"FStar.Monotonic.Heap.gref_of",
"Prims.unit"
] | [] | true | false | true | false | false | let is_mm_gref_of a t rel =
| is_mm_aref_of (gref_of a t rel) | false |
Steel.PCMMap.fst | Steel.PCMMap.composable_maps_assoc_r | val composable_maps_assoc_r (#k #a: _) (p: pcm a) (m0 m1 m2: map k a)
: Lemma (requires composable_maps p m0 m1 /\ composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\ composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 == compose_maps p m0 (compose_maps p m1 m2)) | val composable_maps_assoc_r (#k #a: _) (p: pcm a) (m0 m1 m2: map k a)
: Lemma (requires composable_maps p m0 m1 /\ composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\ composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 == compose_maps p m0 (compose_maps p m1 m2)) | let composable_maps_assoc_r #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m1 key) (Map.sel m2 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m12 = compose_maps p m1 m2 in
introduce forall key.
composable p (Map.sel m0 key) (Map.sel m12 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p (compose_maps p m0 m1) m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal m012 m012') | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 33,
"end_line": 129,
"start_col": 0,
"start_line": 105
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k
/// Compose maps pointwise
let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k)
/// Composability is commutative
let composable_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma (composable_maps p m0 m1 <==>
composable_maps p m1 m0)
= ()
/// Composition is commutative
let compose_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma
(requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0)
= let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key.
Map.sel m01 key == Map.sel m10 key
with ( p.comm (Map.sel m0 key) (Map.sel m1 key) );
assert (Map.equal m01 m10)
/// Composability is left-associative
let composable_maps_assoc_l #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m0 key) (Map.sel m1 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m01 = compose_maps p m0 m1 in
introduce forall key.
composable p (Map.sel m01 key) (Map.sel m2 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p m01 m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal
(compose_maps p (compose_maps p m0 m1) m2)
(compose_maps p m0 (compose_maps p m1 m2))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: FStar.PCM.pcm a ->
m0: Steel.PCMMap.map k a ->
m1: Steel.PCMMap.map k a ->
m2: Steel.PCMMap.map k a
-> FStar.Pervasives.Lemma
(requires
Steel.PCMMap.composable_maps p m0 m1 /\
Steel.PCMMap.composable_maps p (Steel.PCMMap.compose_maps p m0 m1) m2)
(ensures
Steel.PCMMap.composable_maps p m1 m2 /\
Steel.PCMMap.composable_maps p m0 (Steel.PCMMap.compose_maps p m1 m2) /\
Steel.PCMMap.compose_maps p (Steel.PCMMap.compose_maps p m0 m1) m2 ==
Steel.PCMMap.compose_maps p m0 (Steel.PCMMap.compose_maps p m1 m2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"Steel.PCMMap.map",
"Prims._assert",
"FStar.Map.equal",
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eq2",
"FStar.Map.sel",
"FStar.PCM.__proj__Mkpcm__item__assoc_r",
"Prims.squash",
"Steel.PCMMap.compose_maps",
"FStar.PCM.composable",
"Prims.l_and",
"Steel.PCMMap.composable_maps",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let composable_maps_assoc_r #k #a (p: pcm a) (m0: map k a) (m1: map k a) (m2: map k a)
: Lemma (requires composable_maps p m0 m1 /\ composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\ composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 == compose_maps p m0 (compose_maps p m1 m2)) =
| introduce forall key . composable p (Map.sel m1 key) (Map.sel m2 key)
with (p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key));
let m12 = compose_maps p m1 m2 in
introduce forall key . composable p (Map.sel m0 key) (Map.sel m12 key)
with (p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key));
let m012 = compose_maps p (compose_maps p m0 m1) m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key . Map.sel m012 key == Map.sel m012' key
with (p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key));
assert (Map.equal m012 m012') | false |
FStar.Monotonic.Heap.fst | FStar.Monotonic.Heap.upd_ref_of | val upd_ref_of
(a: aref)
(t: Type0)
(rel: preorder t)
(h1 h2: heap)
(x: t)
: Lemma
(requires (aref_live_at h1 a t rel /\ aref_live_at h2 a t rel))
(ensures (aref_live_at h2 a t rel /\ upd h1 (ref_of h2 a t rel) x == upd h1 (gref_of a t rel) x))
[SMTPat (upd h1 (ref_of h2 a t rel) x)] | val upd_ref_of
(a: aref)
(t: Type0)
(rel: preorder t)
(h1 h2: heap)
(x: t)
: Lemma
(requires (aref_live_at h1 a t rel /\ aref_live_at h2 a t rel))
(ensures (aref_live_at h2 a t rel /\ upd h1 (ref_of h2 a t rel) x == upd h1 (gref_of a t rel) x))
[SMTPat (upd h1 (ref_of h2 a t rel) x)] | let upd_ref_of a t rel h1 h2 x =
lemma_heap_equality_upd_same_addr h1 (ref_of h2 a t rel) (gref_of a t rel) x | {
"file_name": "ulib/FStar.Monotonic.Heap.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 78,
"end_line": 331,
"start_col": 0,
"start_line": 330
} | (*
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.Monotonic.Heap
open FStar.Preorder
open FStar.Classical
module F = FStar.FunctionalExtensionality
private noeq type heap_rec = {
next_addr: pos;
memory : F.restricted_t pos (fun (x:pos)
-> option (a:Type0 & rel:(option (preorder a)) & b:bool & a))
//type, preorder, mm flag, and value
}
let heap = h:heap_rec{(forall (n:nat). n >= h.next_addr ==> None? (h.memory n))}
let equal h1 h2 =
let _ = () in
h1.next_addr = h2.next_addr /\
FStar.FunctionalExtensionality.feq h1.memory h2.memory
let equal_extensional h1 h2 = ()
let emp = {
next_addr = 1;
memory = F.on_dom pos (fun r -> None)
}
let next_addr h = h.next_addr
noeq
type core_mref (a:Type0) : Type0 = {
addr: (x: nat { x > 0 } );
init: a;
mm: bool; //manually managed flag
}
let addr_of #a #rel r = r.addr
let is_mm #a #rel r = r.mm
let contains #a #rel h r =
let _ = () in
Some? (h.memory r.addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory r.addr in
a == a1 /\ Some? pre_opt /\ Some?.v pre_opt == rel /\ mm = r.mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let addr_unused_in n h = n <> 0 && None? (h.memory n)
let not_addr_unused_in_nullptr h = ()
let unused_in #a #rel r h = addr_unused_in (addr_of r) h
let sel_tot #a #rel h r =
let Some (| _, _, _, x |) = h.memory r.addr in
x
//
// We want to provide a `sel` API to the client that does not require a
// `contains` precondition, so that the clients don't have to prove it at
// every use of `sel`
//
// To do so, we need to be able to branch on whether the ref is contained in the heap
//
// But that's a problem since `contains` is in prop
//
// The following function assumes a boolean returning version of contains
// We could implement is using the classical strong excluded middle axiom,
// but we prefer to assume an specialized instance of it
//
assume val contains_bool (#a:Type0) (#rel:preorder a) (h:heap) (r:mref a rel)
: GTot (b:bool{b <==> (h `contains` r)})
let sel #a #rel h r =
if h `contains_bool` r
then sel_tot #a h r
else r.init
let upd_tot' (#a: Type0) (#rel: preorder a) (h: heap) (r: mref a rel) (x: a) =
{ h with memory = F.on_dom pos (fun r' -> if r.addr = r'
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let upd_tot #a #rel h r x = upd_tot' h r x
let upd #a #rel h r x =
if h `contains_bool` r
then upd_tot' h r x
else
if r.addr >= h.next_addr
then
{ next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
else
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let alloc #a rel h x mm =
let r = { addr = h.next_addr; init = x; mm = mm } in
r, { next_addr = r.addr + 1;
memory = F.on_dom pos (fun r' -> if r' = r.addr
then Some (| a, Some rel, r.mm, x |)
else h.memory r') }
let free_mm #a #rel h r =
{ h with memory = F.on_dom pos (fun r' -> if r' = r.addr then None else h.memory r') }
(*
* update of a well-typed mreference
*)
private let lemma_upd_contains_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (h0 `contains` r ==>
(let h1 = upd h0 r x in
(forall (b:Type) (rel:preorder b) (r':mref b rel). (h0 `contains` r' /\ addr_of r' = addr_of r) ==> sel h1 r' == x /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' <==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1))))
= ()
(*
* update of a mreference that is mapped but not necessarily well-typed
* we cannot prove that h0 `contains` r' ==> h1 `contains` r'
* because consider that in h0 (r:mref a) contains (| b, y:b |),
* and that (r':mref b) s.t. r'.addr = r.addr
* in h0, r' is well-typed, but in h1 it's not
*)
private let lemma_upd_contains_not_necessarily_well_typed_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma ((~ (r `unused_in` h0)) ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). (r'.addr <> r.addr /\ h0 `contains` r') ==> h1 `contains` r') /\
(forall (b:Type) (#rel:preorder b) (r':mref b rel). r' `unused_in` h0 <==> r' `unused_in` h1)))
= ()
(*
* update of an unused mreference
*)
private let lemma_upd_unused_test
(#a:Type) (#rel:preorder a) (h0:heap) (r:mref a rel) (x:a)
:Lemma (r `unused_in` h0 ==>
(let h1 = upd h0 r x in
h1 `contains` r /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1))))
= ()
(*
* alloc and alloc_mm behaves just like upd of an unmapped mreference
*)
private let lemma_alloc_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let (r, h1) = alloc rel h0 x mm in
r `unused_in` h0 /\
h1 `contains` r /\
is_mm r = mm /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==> sel h0 r' == sel h1 r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). h0 `contains` r' ==> h1 `contains` r') /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). ~ (r' `unused_in` h0) ==> ~ (r' `unused_in` h1)))
= ()
private let lemma_free_mm_test (#a:Type) (rel:preorder a) (h0:heap) (r:mref a rel{h0 `contains` r /\ is_mm r})
:Lemma (let h1 = free_mm h0 r in
r `unused_in` h1 /\
(forall (b:Type) (rel:preorder b) (r':mref b rel). addr_of r' <> addr_of r ==>
((sel h0 r' == sel h1 r' /\
(h0 `contains` r' <==> h1 `contains` r') /\
(r' `unused_in` h0 <==> r' `unused_in` h1)))))
= ()
private let lemma_alloc_fresh_test (#a:Type) (rel:preorder a) (h0:heap) (x:a) (mm:bool)
:Lemma (let r, h1 = alloc rel h0 x mm in
fresh r h0 h1 /\ modifies Set.empty h0 h1)
= ()
let lemma_ref_unused_iff_addr_unused #a #rel h r = ()
let lemma_contains_implies_used #a #rel h r = ()
let lemma_distinct_addrs_distinct_types #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_distinct_addrs_distinct_preorders u = ()
let lemma_distinct_addrs_distinct_mm u = ()
let lemma_distinct_addrs_unused #a #b #rel1 #rel2 h r1 r2 = ()
let lemma_alloc #a rel h0 x mm =
let r, h1 = alloc rel h0 x mm in
let h1' = upd h0 r x in
assert (equal h1 h1')
let lemma_free_mm_sel #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_contains #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_mm_unused #a #b #rel1 #rel2 h0 r1 r2 = ()
let lemma_free_addr_unused_in #a #rel h r n = ()
let lemma_sel_same_addr #a #rel h r1 r2 = ()
let lemma_sel_upd1 #a #rel h r1 x r2 = ()
let lemma_sel_upd2 #a #b #rel1 #rel2 h r1 r2 x = ()
let lemma_mref_injectivity = ()
let lemma_in_dom_emp #a #rel r = ()
let lemma_upd_contains #a #rel h r x = ()
let lemma_well_typed_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_unused_upd_contains #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_contains_different_addr #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_upd_unused #a #b #rel1 #rel2 h r1 x r2 = ()
let lemma_contains_upd_modifies #a #rel h r x = ()
let lemma_unused_upd_modifies #a #rel h r x = ()
let lemma_sel_equals_sel_tot_for_contained_refs #a #rel h r = ()
let lemma_upd_equals_upd_tot_for_contained_refs #a #rel h r x = ()
let lemma_modifies_and_equal_dom_sel_diff_addr #a #rel s h0 h1 r = ()
let lemma_heap_equality_upd_same_addr #a #rel h r1 r2 x =
assert (equal (upd h r1 x) (upd h r2 x))
let lemma_heap_equality_cancel_same_mref_upd #a #rel h r x y =
let h0 = upd (upd h r x) r y in
let h1 = upd h r y in
assert (equal h0 h1)
let lemma_heap_equality_upd_with_sel #a #rel h r =
let h' = upd h r (sel h r) in
let Some (| _, _, _, _ |) = h.memory r.addr in
assert (equal h h')
let lemma_heap_equality_commute_distinct_upds #a #b #rel_a #rel_b h r1 r2 x y =
let h0 = upd (upd h r1 x) r2 y in
let h1 = upd (upd h r2 y) r1 x in
assert (equal h0 h1)
let lemma_next_addr_upd_tot #_ #_ _ _ _ = ()
let lemma_next_addr_upd #_ #_ _ _ _ = ()
let lemma_next_addr_alloc #_ _ _ _ _ = ()
let lemma_next_addr_free_mm #_ #_ _ _ = ()
let lemma_next_addr_contained_refs_addr #_ #_ _ _ = ()
(*** Untyped views of references *)
(* Definition and ghost decidable equality *)
noeq type aref' :Type0 = {
a_addr: (x: nat { x > 0 } );
a_mm: bool; //manually managed flag
}
let aref = aref'
let dummy_aref = {
a_addr = 1;
a_mm = false;
}
let aref_equal a1 a2 = a1.a_addr = a2.a_addr && a1.a_mm = a2.a_mm
(* Introduction rule *)
let aref_of #t #rel r = {
a_addr = r.addr;
a_mm = r.mm;
}
(* Operators lifted from ref *)
let addr_of_aref a = a.a_addr
let addr_of_aref_of #t #rel r = ()
let aref_is_mm a = a.a_mm
let is_mm_aref_of #t #rel r = ()
let aref_unused_in a h = None? (h.memory a.a_addr)
let unused_in_aref_of #t #rel r h = ()
let contains_aref_unused_in #a #rel h x y = ()
(* Elimination rule *)
let aref_live_at (h: heap) (a: aref) (t: Type0) (rel: preorder t) =
let _ = () in
Some? (h.memory a.a_addr) /\
(let Some (| a1, pre_opt, mm, _ |) = h.memory a.a_addr in
t == a1 /\ Some? pre_opt /\ Some?.v pre_opt === rel /\ mm == a.a_mm) //using `===` here, since otherwise typechecker fails with a and a1 being different types, why?
let ref_of'
(h: heap)
(a: aref)
(t: Type0)
(rel: preorder t)
: Pure (mref t rel)
(requires (aref_live_at h a t rel))
(ensures (fun _ -> True))
= let Some (| _, pre_opt, _, x |) = h.memory a.a_addr in
{
addr = a.a_addr;
init = x;
mm = a.a_mm
}
let gref_of a t rel =
let m : squash (exists (h: heap) . aref_live_at h a t rel) = () in
let l : (exists (h: heap) . aref_live_at h a t rel) =
Squash.join_squash #(h: heap & aref_live_at h a t rel) m
in
let k : (exists (h: heap { aref_live_at h a t rel} ) . squash True ) =
FStar.Squash.bind_squash
#(h: heap & aref_live_at h a t rel)
#(h: (h: heap { aref_live_at h a t rel} ) & squash True)
l
(fun h -> let (| h', _ |) = h in Squash.return_squash (| h', () |) )
in
let h = FStar.ErasedLogic.exists_proj1 #(h: heap {aref_live_at h a t rel}) #(fun _ -> squash True) k in
ref_of' h a t rel
let ref_of h a t rel = ref_of' h a t rel
let aref_live_at_aref_of h #t #rel r = ()
let contains_gref_of h a t rel = ()
let aref_of_gref_of a t rel = ()
let addr_of_gref_of a t rel = addr_of_aref_of (gref_of a t rel)
let is_mm_gref_of a t rel = is_mm_aref_of (gref_of a t rel)
let unused_in_gref_of a t rel h = unused_in_aref_of (gref_of a t rel) h
let sel_ref_of a t rel h1 h2 = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Monotonic.Heap.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: FStar.Monotonic.Heap.aref ->
t: Type0 ->
rel: FStar.Preorder.preorder t ->
h1: FStar.Monotonic.Heap.heap ->
h2: FStar.Monotonic.Heap.heap ->
x: t
-> FStar.Pervasives.Lemma
(requires
FStar.Monotonic.Heap.aref_live_at h1 a t rel /\ FStar.Monotonic.Heap.aref_live_at h2 a t rel
)
(ensures
FStar.Monotonic.Heap.aref_live_at h2 a t rel /\
FStar.Monotonic.Heap.upd h1 (FStar.Monotonic.Heap.ref_of h2 a t rel) x ==
FStar.Monotonic.Heap.upd h1 (FStar.Monotonic.Heap.gref_of a t rel) x)
[SMTPat (FStar.Monotonic.Heap.upd h1 (FStar.Monotonic.Heap.ref_of h2 a t rel) x)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Monotonic.Heap.aref",
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.lemma_heap_equality_upd_same_addr",
"FStar.Monotonic.Heap.ref_of",
"FStar.Monotonic.Heap.gref_of",
"Prims.unit"
] | [] | true | false | true | false | false | let upd_ref_of a t rel h1 h2 x =
| lemma_heap_equality_upd_same_addr h1 (ref_of h2 a t rel) (gref_of a t rel) x | false |
Steel.PCMMap.fst | Steel.PCMMap.is_unit | val is_unit (#k #a: _) (p: pcm a) (m: map k a)
: Lemma
(composable_maps p (Map.const p.p.one) m /\ (compose_maps p (Map.const p.p.one) m) `Map.equal` m /\
(compose_maps p m (Map.const p.p.one)) `Map.equal` m) | val is_unit (#k #a: _) (p: pcm a) (m: map k a)
: Lemma
(composable_maps p (Map.const p.p.one) m /\ (compose_maps p (Map.const p.p.one) m) `Map.equal` m /\
(compose_maps p m (Map.const p.p.one)) `Map.equal` m) | let is_unit #k #a (p:pcm a) (m:map k a)
: Lemma (composable_maps p (Map.const p.p.one) m /\
compose_maps p (Map.const p.p.one) m `Map.equal` m /\
compose_maps p m (Map.const p.p.one) `Map.equal` m)
= introduce forall k. composable p p.p.one (Map.sel m k)
with (
p.is_unit (Map.sel m k)
);
introduce forall k. Map.sel (compose_maps p (Map.const p.p.one) m) k == Map.sel m k /\
Map.sel (compose_maps p m (Map.const p.p.one)) k == Map.sel m k
with (
p.is_unit (Map.sel m k);
p.comm p.p.one (Map.sel m k)
) | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 155,
"start_col": 0,
"start_line": 142
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k
/// Compose maps pointwise
let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k)
/// Composability is commutative
let composable_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma (composable_maps p m0 m1 <==>
composable_maps p m1 m0)
= ()
/// Composition is commutative
let compose_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma
(requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0)
= let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key.
Map.sel m01 key == Map.sel m10 key
with ( p.comm (Map.sel m0 key) (Map.sel m1 key) );
assert (Map.equal m01 m10)
/// Composability is left-associative
let composable_maps_assoc_l #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m0 key) (Map.sel m1 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m01 = compose_maps p m0 m1 in
introduce forall key.
composable p (Map.sel m01 key) (Map.sel m2 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p m01 m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal
(compose_maps p (compose_maps p m0 m1) m2)
(compose_maps p m0 (compose_maps p m1 m2)))
/// Composability is right-associative
let composable_maps_assoc_r #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m1 key) (Map.sel m2 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m12 = compose_maps p m1 m2 in
introduce forall key.
composable p (Map.sel m0 key) (Map.sel m12 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p (compose_maps p m0 m1) m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal m012 m012')
/// The core of the constructed PCM
/// The unit is just the pointwise unit
let pcm'_map_of_pcm (#a:_) (k:eqtype) (p:pcm a)
: pcm' (map k a)
= {
composable = composable_maps p;
op = compose_maps p;
one = Map.const p.p.one
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.PCM.pcm a -> m: Steel.PCMMap.map k a
-> FStar.Pervasives.Lemma
(ensures
Steel.PCMMap.composable_maps p (FStar.Map.const (Mkpcm'?.one (Mkpcm?.p p))) m /\
FStar.Map.equal (Steel.PCMMap.compose_maps p (FStar.Map.const (Mkpcm'?.one (Mkpcm?.p p))) m) m /\
FStar.Map.equal (Steel.PCMMap.compose_maps p m (FStar.Map.const (Mkpcm'?.one (Mkpcm?.p p)))) m
) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"Steel.PCMMap.map",
"FStar.Classical.Sugar.forall_intro",
"Prims.l_and",
"Prims.eq2",
"FStar.Map.sel",
"Steel.PCMMap.compose_maps",
"FStar.Map.const",
"FStar.PCM.__proj__Mkpcm'__item__one",
"FStar.PCM.__proj__Mkpcm__item__p",
"FStar.PCM.__proj__Mkpcm__item__comm",
"Prims.unit",
"FStar.PCM.__proj__Mkpcm__item__is_unit",
"Prims.squash",
"FStar.PCM.composable",
"Prims.l_True",
"Steel.PCMMap.composable_maps",
"FStar.Map.equal",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let is_unit #k #a (p: pcm a) (m: map k a)
: Lemma
(composable_maps p (Map.const p.p.one) m /\ (compose_maps p (Map.const p.p.one) m) `Map.equal` m /\
(compose_maps p m (Map.const p.p.one)) `Map.equal` m) =
| introduce forall k . composable p p.p.one (Map.sel m k)
with (p.is_unit (Map.sel m k));
introduce forall k . Map.sel (compose_maps p (Map.const p.p.one) m) k == Map.sel m k /\
Map.sel (compose_maps p m (Map.const p.p.one)) k == Map.sel m k
with (p.is_unit (Map.sel m k);
p.comm p.p.one (Map.sel m k)) | false |
Steel.PCMMap.fst | Steel.PCMMap.composable_maps_assoc_l | val composable_maps_assoc_l (#k #a: _) (p: pcm a) (m0 m1 m2: map k a)
: Lemma (requires composable_maps p m1 m2 /\ composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\ composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 == compose_maps p m0 (compose_maps p m1 m2)) | val composable_maps_assoc_l (#k #a: _) (p: pcm a) (m0 m1 m2: map k a)
: Lemma (requires composable_maps p m1 m2 /\ composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\ composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 == compose_maps p m0 (compose_maps p m1 m2)) | let composable_maps_assoc_l #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m0 key) (Map.sel m1 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m01 = compose_maps p m0 m1 in
introduce forall key.
composable p (Map.sel m01 key) (Map.sel m2 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p m01 m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal
(compose_maps p (compose_maps p m0 m1) m2)
(compose_maps p m0 (compose_maps p m1 m2))) | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 60,
"end_line": 102,
"start_col": 0,
"start_line": 76
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k
/// Compose maps pointwise
let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k)
/// Composability is commutative
let composable_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma (composable_maps p m0 m1 <==>
composable_maps p m1 m0)
= ()
/// Composition is commutative
let compose_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma
(requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0)
= let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key.
Map.sel m01 key == Map.sel m10 key
with ( p.comm (Map.sel m0 key) (Map.sel m1 key) );
assert (Map.equal m01 m10) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: FStar.PCM.pcm a ->
m0: Steel.PCMMap.map k a ->
m1: Steel.PCMMap.map k a ->
m2: Steel.PCMMap.map k a
-> FStar.Pervasives.Lemma
(requires
Steel.PCMMap.composable_maps p m1 m2 /\
Steel.PCMMap.composable_maps p m0 (Steel.PCMMap.compose_maps p m1 m2))
(ensures
Steel.PCMMap.composable_maps p m0 m1 /\
Steel.PCMMap.composable_maps p (Steel.PCMMap.compose_maps p m0 m1) m2 /\
Steel.PCMMap.compose_maps p (Steel.PCMMap.compose_maps p m0 m1) m2 ==
Steel.PCMMap.compose_maps p m0 (Steel.PCMMap.compose_maps p m1 m2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"Steel.PCMMap.map",
"Prims._assert",
"FStar.Map.equal",
"Steel.PCMMap.compose_maps",
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eq2",
"FStar.Map.sel",
"FStar.PCM.__proj__Mkpcm__item__assoc",
"Prims.squash",
"FStar.PCM.composable",
"Prims.l_and",
"Steel.PCMMap.composable_maps",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let composable_maps_assoc_l #k #a (p: pcm a) (m0: map k a) (m1: map k a) (m2: map k a)
: Lemma (requires composable_maps p m1 m2 /\ composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\ composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 == compose_maps p m0 (compose_maps p m1 m2)) =
| introduce forall key . composable p (Map.sel m0 key) (Map.sel m1 key)
with (p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key));
let m01 = compose_maps p m0 m1 in
introduce forall key . composable p (Map.sel m01 key) (Map.sel m2 key)
with (p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key));
let m012 = compose_maps p m01 m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key . Map.sel m012 key == Map.sel m012' key
with (p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key));
assert (Map.equal (compose_maps p (compose_maps p m0 m1) m2)
(compose_maps p m0 (compose_maps p m1 m2))) | false |
Steel.PCMMap.fst | Steel.PCMMap.pointwise | val pointwise (#a: _) (k: eqtype) (p: pcm a) : pcm (map k a) | val pointwise (#a: _) (k: eqtype) (p: pcm a) : pcm (map k a) | let pointwise (#a:_) (k:eqtype) (p:pcm a)
: pcm (map k a)
= {
p = pcm'_map_of_pcm k p;
comm = (fun m0 m1 -> compose_maps_comm p m0 m1);
assoc = (fun m0 m1 m2 -> composable_maps_assoc_l p m0 m1 m2);
assoc_r = (fun m0 m1 m2 -> composable_maps_assoc_r p m0 m1 m2);
is_unit = (fun m -> is_unit p m);
refine = (fun m -> forall k. p.refine (Map.sel m k))
} | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 168,
"start_col": 0,
"start_line": 159
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k
/// Compose maps pointwise
let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k)
/// Composability is commutative
let composable_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma (composable_maps p m0 m1 <==>
composable_maps p m1 m0)
= ()
/// Composition is commutative
let compose_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma
(requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0)
= let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key.
Map.sel m01 key == Map.sel m10 key
with ( p.comm (Map.sel m0 key) (Map.sel m1 key) );
assert (Map.equal m01 m10)
/// Composability is left-associative
let composable_maps_assoc_l #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m0 key) (Map.sel m1 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m01 = compose_maps p m0 m1 in
introduce forall key.
composable p (Map.sel m01 key) (Map.sel m2 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p m01 m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal
(compose_maps p (compose_maps p m0 m1) m2)
(compose_maps p m0 (compose_maps p m1 m2)))
/// Composability is right-associative
let composable_maps_assoc_r #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m1 key) (Map.sel m2 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m12 = compose_maps p m1 m2 in
introduce forall key.
composable p (Map.sel m0 key) (Map.sel m12 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p (compose_maps p m0 m1) m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal m012 m012')
/// The core of the constructed PCM
/// The unit is just the pointwise unit
let pcm'_map_of_pcm (#a:_) (k:eqtype) (p:pcm a)
: pcm' (map k a)
= {
composable = composable_maps p;
op = compose_maps p;
one = Map.const p.p.one
}
/// The unit is really a unit
let is_unit #k #a (p:pcm a) (m:map k a)
: Lemma (composable_maps p (Map.const p.p.one) m /\
compose_maps p (Map.const p.p.one) m `Map.equal` m /\
compose_maps p m (Map.const p.p.one) `Map.equal` m)
= introduce forall k. composable p p.p.one (Map.sel m k)
with (
p.is_unit (Map.sel m k)
);
introduce forall k. Map.sel (compose_maps p (Map.const p.p.one) m) k == Map.sel m k /\
Map.sel (compose_maps p m (Map.const p.p.one)) k == Map.sel m k
with (
p.is_unit (Map.sel m k);
p.comm p.p.one (Map.sel m k)
)
/// The main function of this module: | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k: Prims.eqtype -> p: FStar.PCM.pcm a -> FStar.PCM.pcm (Steel.PCMMap.map k a) | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"FStar.PCM.Mkpcm",
"Steel.PCMMap.map",
"Steel.PCMMap.pcm'_map_of_pcm",
"FStar.PCM.__proj__Mkpcm'__item__composable",
"Steel.PCMMap.compose_maps_comm",
"Prims.unit",
"Prims.l_and",
"FStar.PCM.__proj__Mkpcm'__item__op",
"Steel.PCMMap.composable_maps_assoc_l",
"Steel.PCMMap.composable_maps_assoc_r",
"Steel.PCMMap.is_unit",
"Prims.l_Forall",
"FStar.PCM.__proj__Mkpcm__item__refine",
"FStar.Map.sel",
"Prims.prop"
] | [] | false | false | false | false | false | let pointwise (#a: _) (k: eqtype) (p: pcm a) : pcm (map k a) =
| {
p = pcm'_map_of_pcm k p;
comm = (fun m0 m1 -> compose_maps_comm p m0 m1);
assoc = (fun m0 m1 m2 -> composable_maps_assoc_l p m0 m1 m2);
assoc_r = (fun m0 m1 m2 -> composable_maps_assoc_r p m0 m1 m2);
is_unit = (fun m -> is_unit p m);
refine = (fun m -> forall k. p.refine (Map.sel m k))
} | false |
Steel.PCMMap.fst | Steel.PCMMap.compatible_pointwise | val compatible_pointwise (#a #k: _) (p: pcm a) (m0 m1: map k a)
: Lemma (requires compatible (pointwise k p) m0 m1)
(ensures forall k. compatible p (Map.sel m0 k) (Map.sel m1 k)) | val compatible_pointwise (#a #k: _) (p: pcm a) (m0 m1: map k a)
: Lemma (requires compatible (pointwise k p) m0 m1)
(ensures forall k. compatible p (Map.sel m0 k) (Map.sel m1 k)) | let compatible_pointwise #a #k
(p:pcm a)
(m0 m1:map k a)
: Lemma
(requires compatible (pointwise k p) m0 m1)
(ensures forall k. compatible p (Map.sel m0 k) (Map.sel m1 k))
= let pcm' = pointwise k p in
introduce forall k. compatible p (Map.sel m0 k) (Map.sel m1 k)
with (
eliminate exists frame.
composable pcm' m0 frame /\ op pcm' frame m0 == m1
returns _
with _. (
introduce exists (frame:a).
composable p
(Map.sel m0 k)
frame /\
op p frame (Map.sel m0 k) == Map.sel m1 k
with (Map.sel frame k)
and ())) | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 16,
"end_line": 192,
"start_col": 0,
"start_line": 173
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k
/// Compose maps pointwise
let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k)
/// Composability is commutative
let composable_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma (composable_maps p m0 m1 <==>
composable_maps p m1 m0)
= ()
/// Composition is commutative
let compose_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma
(requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0)
= let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key.
Map.sel m01 key == Map.sel m10 key
with ( p.comm (Map.sel m0 key) (Map.sel m1 key) );
assert (Map.equal m01 m10)
/// Composability is left-associative
let composable_maps_assoc_l #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m0 key) (Map.sel m1 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m01 = compose_maps p m0 m1 in
introduce forall key.
composable p (Map.sel m01 key) (Map.sel m2 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p m01 m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal
(compose_maps p (compose_maps p m0 m1) m2)
(compose_maps p m0 (compose_maps p m1 m2)))
/// Composability is right-associative
let composable_maps_assoc_r #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m1 key) (Map.sel m2 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m12 = compose_maps p m1 m2 in
introduce forall key.
composable p (Map.sel m0 key) (Map.sel m12 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p (compose_maps p m0 m1) m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal m012 m012')
/// The core of the constructed PCM
/// The unit is just the pointwise unit
let pcm'_map_of_pcm (#a:_) (k:eqtype) (p:pcm a)
: pcm' (map k a)
= {
composable = composable_maps p;
op = compose_maps p;
one = Map.const p.p.one
}
/// The unit is really a unit
let is_unit #k #a (p:pcm a) (m:map k a)
: Lemma (composable_maps p (Map.const p.p.one) m /\
compose_maps p (Map.const p.p.one) m `Map.equal` m /\
compose_maps p m (Map.const p.p.one) `Map.equal` m)
= introduce forall k. composable p p.p.one (Map.sel m k)
with (
p.is_unit (Map.sel m k)
);
introduce forall k. Map.sel (compose_maps p (Map.const p.p.one) m) k == Map.sel m k /\
Map.sel (compose_maps p m (Map.const p.p.one)) k == Map.sel m k
with (
p.is_unit (Map.sel m k);
p.comm p.p.one (Map.sel m k)
)
/// The main function of this module:
/// Given a [k] and [p:pcm a], lift it pointwise
let pointwise (#a:_) (k:eqtype) (p:pcm a)
: pcm (map k a)
= {
p = pcm'_map_of_pcm k p;
comm = (fun m0 m1 -> compose_maps_comm p m0 m1);
assoc = (fun m0 m1 m2 -> composable_maps_assoc_l p m0 m1 m2);
assoc_r = (fun m0 m1 m2 -> composable_maps_assoc_r p m0 m1 m2);
is_unit = (fun m -> is_unit p m);
refine = (fun m -> forall k. p.refine (Map.sel m k))
}
/// Now some constructions that allow us to lift frame-preserving updates | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.PCM.pcm a -> m0: Steel.PCMMap.map k a -> m1: Steel.PCMMap.map k a
-> FStar.Pervasives.Lemma (requires FStar.PCM.compatible (Steel.PCMMap.pointwise k p) m0 m1)
(ensures forall (k: k). FStar.PCM.compatible p (FStar.Map.sel m0 k) (FStar.Map.sel m1 k)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"Steel.PCMMap.map",
"FStar.Classical.Sugar.forall_intro",
"FStar.PCM.compatible",
"FStar.Map.sel",
"FStar.Classical.Sugar.exists_elim",
"Prims.l_and",
"FStar.PCM.composable",
"Prims.eq2",
"FStar.PCM.op",
"Prims.l_Exists",
"Prims.squash",
"FStar.Classical.Sugar.exists_intro",
"Prims.unit",
"Steel.PCMMap.pointwise",
"Prims.l_Forall",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let compatible_pointwise #a #k (p: pcm a) (m0: map k a) (m1: map k a)
: Lemma (requires compatible (pointwise k p) m0 m1)
(ensures forall k. compatible p (Map.sel m0 k) (Map.sel m1 k)) =
| let pcm' = pointwise k p in
introduce forall k . compatible p (Map.sel m0 k) (Map.sel m1 k)
with (eliminate exists frame.
composable pcm' m0 frame /\ op pcm' frame m0 == m1
returns _
with _.
(introduce exists (frame: a).composable p (Map.sel m0 k) frame /\
op p frame (Map.sel m0 k) == Map.sel m1 k
with (Map.sel frame k)
and ())) | false |
Steel.PCMMap.fst | Steel.PCMMap.compatible_pointwise_upd | val compatible_pointwise_upd
(#a: _)
(#k: eqtype)
(p: pcm a)
(v1 full_v1: a)
(m0 full_m0: map k a)
(key: k)
: Lemma (requires compatible p v1 full_v1 /\ compatible (pointwise k p) m0 full_m0)
(ensures compatible (pointwise k p) (Map.upd m0 key v1) (Map.upd full_m0 key full_v1)) | val compatible_pointwise_upd
(#a: _)
(#k: eqtype)
(p: pcm a)
(v1 full_v1: a)
(m0 full_m0: map k a)
(key: k)
: Lemma (requires compatible p v1 full_v1 /\ compatible (pointwise k p) m0 full_m0)
(ensures compatible (pointwise k p) (Map.upd m0 key v1) (Map.upd full_m0 key full_v1)) | let compatible_pointwise_upd #a (#k:eqtype)
(p:pcm a)
(v1 full_v1:a)
(m0 full_m0:map k a)
(key:k)
: Lemma
(requires
compatible p v1 full_v1 /\
compatible (pointwise k p) m0 full_m0)
(ensures
compatible (pointwise k p) (Map.upd m0 key v1)
(Map.upd full_m0 key full_v1))
= compatible_pointwise p m0 full_m0;
assert (compatible p (Map.sel m0 key) (Map.sel full_m0 key));
let m1 = (Map.upd m0 key v1) in
let full_m1 = (Map.upd full_m0 key full_v1) in
let p' = pointwise k p in
eliminate exists (frame_m0:_). composable p' m0 frame_m0 /\ op p' frame_m0 m0 == full_m0
returns _
with _. (
eliminate exists (frame0:_). composable p v1 frame0 /\ op p frame0 v1 == full_v1
returns _
with _. (
introduce exists (frame:_).
composable p' m1 frame /\ op p' frame m1 == full_m1
with (Map.upd frame_m0 key frame0)
and (
let w = Map.upd frame_m0 key frame0 in
assert (Map.equal (compose_maps p w m1) full_m1)
))) | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 227,
"start_col": 0,
"start_line": 198
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k
/// Compose maps pointwise
let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k)
/// Composability is commutative
let composable_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma (composable_maps p m0 m1 <==>
composable_maps p m1 m0)
= ()
/// Composition is commutative
let compose_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma
(requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0)
= let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key.
Map.sel m01 key == Map.sel m10 key
with ( p.comm (Map.sel m0 key) (Map.sel m1 key) );
assert (Map.equal m01 m10)
/// Composability is left-associative
let composable_maps_assoc_l #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m0 key) (Map.sel m1 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m01 = compose_maps p m0 m1 in
introduce forall key.
composable p (Map.sel m01 key) (Map.sel m2 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p m01 m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal
(compose_maps p (compose_maps p m0 m1) m2)
(compose_maps p m0 (compose_maps p m1 m2)))
/// Composability is right-associative
let composable_maps_assoc_r #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m1 key) (Map.sel m2 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m12 = compose_maps p m1 m2 in
introduce forall key.
composable p (Map.sel m0 key) (Map.sel m12 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p (compose_maps p m0 m1) m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal m012 m012')
/// The core of the constructed PCM
/// The unit is just the pointwise unit
let pcm'_map_of_pcm (#a:_) (k:eqtype) (p:pcm a)
: pcm' (map k a)
= {
composable = composable_maps p;
op = compose_maps p;
one = Map.const p.p.one
}
/// The unit is really a unit
let is_unit #k #a (p:pcm a) (m:map k a)
: Lemma (composable_maps p (Map.const p.p.one) m /\
compose_maps p (Map.const p.p.one) m `Map.equal` m /\
compose_maps p m (Map.const p.p.one) `Map.equal` m)
= introduce forall k. composable p p.p.one (Map.sel m k)
with (
p.is_unit (Map.sel m k)
);
introduce forall k. Map.sel (compose_maps p (Map.const p.p.one) m) k == Map.sel m k /\
Map.sel (compose_maps p m (Map.const p.p.one)) k == Map.sel m k
with (
p.is_unit (Map.sel m k);
p.comm p.p.one (Map.sel m k)
)
/// The main function of this module:
/// Given a [k] and [p:pcm a], lift it pointwise
let pointwise (#a:_) (k:eqtype) (p:pcm a)
: pcm (map k a)
= {
p = pcm'_map_of_pcm k p;
comm = (fun m0 m1 -> compose_maps_comm p m0 m1);
assoc = (fun m0 m1 m2 -> composable_maps_assoc_l p m0 m1 m2);
assoc_r = (fun m0 m1 m2 -> composable_maps_assoc_r p m0 m1 m2);
is_unit = (fun m -> is_unit p m);
refine = (fun m -> forall k. p.refine (Map.sel m k))
}
/// Now some constructions that allow us to lift frame-preserving updates
/// If a two maps are compatible, then they are also compatible pointwise
let compatible_pointwise #a #k
(p:pcm a)
(m0 m1:map k a)
: Lemma
(requires compatible (pointwise k p) m0 m1)
(ensures forall k. compatible p (Map.sel m0 k) (Map.sel m1 k))
= let pcm' = pointwise k p in
introduce forall k. compatible p (Map.sel m0 k) (Map.sel m1 k)
with (
eliminate exists frame.
composable pcm' m0 frame /\ op pcm' frame m0 == m1
returns _
with _. (
introduce exists (frame:a).
composable p
(Map.sel m0 k)
frame /\
op p frame (Map.sel m0 k) == Map.sel m1 k
with (Map.sel frame k)
and ()))
/// A very specific lemma for use in lifting frame-preserving updates
///
/// If two maps are compatible, then updating them at a key with | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: FStar.PCM.pcm a ->
v1: a ->
full_v1: a ->
m0: Steel.PCMMap.map k a ->
full_m0: Steel.PCMMap.map k a ->
key: k
-> FStar.Pervasives.Lemma
(requires
FStar.PCM.compatible p v1 full_v1 /\
FStar.PCM.compatible (Steel.PCMMap.pointwise k p) m0 full_m0)
(ensures
FStar.PCM.compatible (Steel.PCMMap.pointwise k p)
(FStar.Map.upd m0 key v1)
(FStar.Map.upd full_m0 key full_v1)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"Steel.PCMMap.map",
"FStar.Classical.Sugar.exists_elim",
"Prims.l_and",
"FStar.PCM.composable",
"Prims.eq2",
"FStar.PCM.op",
"Prims.l_Exists",
"FStar.Map.t",
"Prims.squash",
"FStar.Classical.Sugar.exists_intro",
"FStar.Map.upd",
"Prims.unit",
"Prims._assert",
"FStar.Map.equal",
"Steel.PCMMap.compose_maps",
"Steel.PCMMap.pointwise",
"FStar.PCM.compatible",
"FStar.Map.sel",
"Steel.PCMMap.compatible_pointwise",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let compatible_pointwise_upd
#a
(#k: eqtype)
(p: pcm a)
(v1: a)
(full_v1: a)
(m0: map k a)
(full_m0: map k a)
(key: k)
: Lemma (requires compatible p v1 full_v1 /\ compatible (pointwise k p) m0 full_m0)
(ensures compatible (pointwise k p) (Map.upd m0 key v1) (Map.upd full_m0 key full_v1)) =
| compatible_pointwise p m0 full_m0;
assert (compatible p (Map.sel m0 key) (Map.sel full_m0 key));
let m1 = (Map.upd m0 key v1) in
let full_m1 = (Map.upd full_m0 key full_v1) in
let p' = pointwise k p in
eliminate exists (frame_m0: _).
composable p' m0 frame_m0 /\ op p' frame_m0 m0 == full_m0
returns _
with _.
(eliminate exists (frame0: _).
composable p v1 frame0 /\ op p frame0 v1 == full_v1
returns _
with _.
(introduce exists (frame: _).composable p' m1 frame /\ op p' frame m1 == full_m1
with (Map.upd frame_m0 key frame0)
and (let w = Map.upd frame_m0 key frame0 in
assert (Map.equal (compose_maps p w m1) full_m1)))) | false |
Steel.PCMMap.fst | Steel.PCMMap.lift_frame_preservation | val lift_frame_preservation
(#a: _)
(#k: eqtype)
(p: pcm a)
(m0 full_m0: map k a)
(v1 full_v1: a)
(key: k)
: Lemma
(requires
(let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
(forall (frame: a{composable p v0 frame}). {:pattern composable p v0 frame}
composable p v1 frame /\ (op p v0 frame == full_v0 ==> op p v1 frame == full_v1))))
(ensures
(let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
let p' = pointwise k p in
(forall (frame: _{composable p' m0 frame}).
composable p' m1 frame /\ (op p' m0 frame == full_m0 ==> op p' m1 frame == full_m1)))) | val lift_frame_preservation
(#a: _)
(#k: eqtype)
(p: pcm a)
(m0 full_m0: map k a)
(v1 full_v1: a)
(key: k)
: Lemma
(requires
(let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
(forall (frame: a{composable p v0 frame}). {:pattern composable p v0 frame}
composable p v1 frame /\ (op p v0 frame == full_v0 ==> op p v1 frame == full_v1))))
(ensures
(let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
let p' = pointwise k p in
(forall (frame: _{composable p' m0 frame}).
composable p' m1 frame /\ (op p' m0 frame == full_m0 ==> op p' m1 frame == full_m1)))) | let lift_frame_preservation #a (#k:eqtype) (p:pcm a)
(m0 full_m0:map k a)
(v1 full_v1:a)
(key:k)
: Lemma
(requires (
let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
(forall (frame:a{composable p v0 frame}). {:pattern composable p v0 frame}
composable p v1 frame /\
(op p v0 frame == full_v0 ==>
op p v1 frame == full_v1))))
(ensures (
let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
let p' = pointwise k p in
(forall (frame:_{composable p' m0 frame}).
composable p' m1 frame /\
(op p' m0 frame == full_m0 ==>
op p' m1 frame == full_m1))))
= let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
let p' = pointwise k p in
introduce forall (frame:_{composable p' m0 frame}).
composable p' m1 frame /\
(op p' m0 frame == full_m0 ==>
op p' m1 frame == full_m1)
with (
introduce _ /\ _
with ()
and ( introduce _ ==> _
with _. (
assert (compose_maps p m1 frame `Map.equal` full_m1)
)
)
) | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 276,
"start_col": 0,
"start_line": 235
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k
/// Compose maps pointwise
let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k)
/// Composability is commutative
let composable_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma (composable_maps p m0 m1 <==>
composable_maps p m1 m0)
= ()
/// Composition is commutative
let compose_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma
(requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0)
= let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key.
Map.sel m01 key == Map.sel m10 key
with ( p.comm (Map.sel m0 key) (Map.sel m1 key) );
assert (Map.equal m01 m10)
/// Composability is left-associative
let composable_maps_assoc_l #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m0 key) (Map.sel m1 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m01 = compose_maps p m0 m1 in
introduce forall key.
composable p (Map.sel m01 key) (Map.sel m2 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p m01 m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal
(compose_maps p (compose_maps p m0 m1) m2)
(compose_maps p m0 (compose_maps p m1 m2)))
/// Composability is right-associative
let composable_maps_assoc_r #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m1 key) (Map.sel m2 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m12 = compose_maps p m1 m2 in
introduce forall key.
composable p (Map.sel m0 key) (Map.sel m12 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p (compose_maps p m0 m1) m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal m012 m012')
/// The core of the constructed PCM
/// The unit is just the pointwise unit
let pcm'_map_of_pcm (#a:_) (k:eqtype) (p:pcm a)
: pcm' (map k a)
= {
composable = composable_maps p;
op = compose_maps p;
one = Map.const p.p.one
}
/// The unit is really a unit
let is_unit #k #a (p:pcm a) (m:map k a)
: Lemma (composable_maps p (Map.const p.p.one) m /\
compose_maps p (Map.const p.p.one) m `Map.equal` m /\
compose_maps p m (Map.const p.p.one) `Map.equal` m)
= introduce forall k. composable p p.p.one (Map.sel m k)
with (
p.is_unit (Map.sel m k)
);
introduce forall k. Map.sel (compose_maps p (Map.const p.p.one) m) k == Map.sel m k /\
Map.sel (compose_maps p m (Map.const p.p.one)) k == Map.sel m k
with (
p.is_unit (Map.sel m k);
p.comm p.p.one (Map.sel m k)
)
/// The main function of this module:
/// Given a [k] and [p:pcm a], lift it pointwise
let pointwise (#a:_) (k:eqtype) (p:pcm a)
: pcm (map k a)
= {
p = pcm'_map_of_pcm k p;
comm = (fun m0 m1 -> compose_maps_comm p m0 m1);
assoc = (fun m0 m1 m2 -> composable_maps_assoc_l p m0 m1 m2);
assoc_r = (fun m0 m1 m2 -> composable_maps_assoc_r p m0 m1 m2);
is_unit = (fun m -> is_unit p m);
refine = (fun m -> forall k. p.refine (Map.sel m k))
}
/// Now some constructions that allow us to lift frame-preserving updates
/// If a two maps are compatible, then they are also compatible pointwise
let compatible_pointwise #a #k
(p:pcm a)
(m0 m1:map k a)
: Lemma
(requires compatible (pointwise k p) m0 m1)
(ensures forall k. compatible p (Map.sel m0 k) (Map.sel m1 k))
= let pcm' = pointwise k p in
introduce forall k. compatible p (Map.sel m0 k) (Map.sel m1 k)
with (
eliminate exists frame.
composable pcm' m0 frame /\ op pcm' frame m0 == m1
returns _
with _. (
introduce exists (frame:a).
composable p
(Map.sel m0 k)
frame /\
op p frame (Map.sel m0 k) == Map.sel m1 k
with (Map.sel frame k)
and ()))
/// A very specific lemma for use in lifting frame-preserving updates
///
/// If two maps are compatible, then updating them at a key with
/// values that are compatible produces compatible maps
let compatible_pointwise_upd #a (#k:eqtype)
(p:pcm a)
(v1 full_v1:a)
(m0 full_m0:map k a)
(key:k)
: Lemma
(requires
compatible p v1 full_v1 /\
compatible (pointwise k p) m0 full_m0)
(ensures
compatible (pointwise k p) (Map.upd m0 key v1)
(Map.upd full_m0 key full_v1))
= compatible_pointwise p m0 full_m0;
assert (compatible p (Map.sel m0 key) (Map.sel full_m0 key));
let m1 = (Map.upd m0 key v1) in
let full_m1 = (Map.upd full_m0 key full_v1) in
let p' = pointwise k p in
eliminate exists (frame_m0:_). composable p' m0 frame_m0 /\ op p' frame_m0 m0 == full_m0
returns _
with _. (
eliminate exists (frame0:_). composable p v1 frame0 /\ op p frame0 v1 == full_v1
returns _
with _. (
introduce exists (frame:_).
composable p' m1 frame /\ op p' frame m1 == full_m1
with (Map.upd frame_m0 key frame0)
and (
let w = Map.upd frame_m0 key frame0 in
assert (Map.equal (compose_maps p w m1) full_m1)
)))
/// If any frame composes with [v0] to produce [full_v0]
/// can also be composed with [v1] to produce [full_v1]
///
/// Then any frame composable with a map contains [v0] yielding a map
/// containing [full_v0], is also composable with a map containing | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: FStar.PCM.pcm a ->
m0: Steel.PCMMap.map k a ->
full_m0: Steel.PCMMap.map k a ->
v1: a ->
full_v1: a ->
key: k
-> FStar.Pervasives.Lemma
(requires
(let v0 = FStar.Map.sel m0 key in
let full_v0 = FStar.Map.sel full_m0 key in
let m1 = FStar.Map.upd m0 key v1 in
let full_m1 = FStar.Map.upd full_m0 key full_v1 in
forall (frame: a{FStar.PCM.composable p v0 frame}).
{:pattern FStar.PCM.composable p v0 frame}
FStar.PCM.composable p v1 frame /\
(FStar.PCM.op p v0 frame == full_v0 ==> FStar.PCM.op p v1 frame == full_v1)))
(ensures
(let v0 = FStar.Map.sel m0 key in
let full_v0 = FStar.Map.sel full_m0 key in
let m1 = FStar.Map.upd m0 key v1 in
let full_m1 = FStar.Map.upd full_m0 key full_v1 in
let p' = Steel.PCMMap.pointwise k p in
forall (frame: Steel.PCMMap.map k a {FStar.PCM.composable p' m0 frame}).
FStar.PCM.composable p' m1 frame /\
(FStar.PCM.op p' m0 frame == full_m0 ==> FStar.PCM.op p' m1 frame == full_m1))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"Steel.PCMMap.map",
"FStar.Classical.Sugar.forall_intro",
"FStar.PCM.composable",
"Prims.l_and",
"Prims.l_imp",
"Prims.eq2",
"FStar.PCM.op",
"FStar.Map.t",
"FStar.Classical.Sugar.and_intro",
"Prims.squash",
"Prims.unit",
"FStar.Classical.Sugar.implies_intro",
"Prims._assert",
"FStar.Map.equal",
"Steel.PCMMap.compose_maps",
"Steel.PCMMap.pointwise",
"FStar.Map.upd",
"FStar.Map.sel",
"Prims.l_Forall",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lift_frame_preservation
#a
(#k: eqtype)
(p: pcm a)
(m0: map k a)
(full_m0: map k a)
(v1: a)
(full_v1: a)
(key: k)
: Lemma
(requires
(let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
(forall (frame: a{composable p v0 frame}). {:pattern composable p v0 frame}
composable p v1 frame /\ (op p v0 frame == full_v0 ==> op p v1 frame == full_v1))))
(ensures
(let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
let p' = pointwise k p in
(forall (frame: _{composable p' m0 frame}).
composable p' m1 frame /\ (op p' m0 frame == full_m0 ==> op p' m1 frame == full_m1)))) =
| let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
let p' = pointwise k p in
introduce forall (frame: _{composable p' m0 frame}) . composable p' m1 frame /\
(op p' m0 frame == full_m0 ==> op p' m1 frame == full_m1)
with (introduce _ /\ _
with ()
and (introduce _ ==> _
with _. (assert ((compose_maps p m1 frame) `Map.equal` full_m1)))) | false |
Steel.PCMMap.fst | Steel.PCMMap.lift_frame_preserving_upd | val lift_frame_preserving_upd
(#a #k: _)
(#p: pcm a)
(v0 v1: Ghost.erased a)
(f: frame_preserving_upd p v0 v1)
(m0: Ghost.erased (map k a))
(key: k{Map.sel m0 key == Ghost.reveal v0})
: frame_preserving_upd (pointwise k p) m0 (Map.upd m0 key v1) | val lift_frame_preserving_upd
(#a #k: _)
(#p: pcm a)
(v0 v1: Ghost.erased a)
(f: frame_preserving_upd p v0 v1)
(m0: Ghost.erased (map k a))
(key: k{Map.sel m0 key == Ghost.reveal v0})
: frame_preserving_upd (pointwise k p) m0 (Map.upd m0 key v1) | let lift_frame_preserving_upd #a #k (#p:pcm a)
(v0 v1: Ghost.erased a)
(f:frame_preserving_upd p v0 v1)
(m0: Ghost.erased (map k a))
(key:k { Map.sel m0 key == Ghost.reveal v0 })
: frame_preserving_upd (pointwise k p) m0 (Map.upd m0 key v1)
= fun full_m0 ->
let p' = pointwise k p in
let full_v0 = Map.sel full_m0 key in
assert (compatible (pointwise _ p) m0 full_m0);
assert (p.refine full_v0);
compatible_pointwise #a #k p m0 full_m0;
assert (compatible p v0 full_v0);
let full_v1 = f full_v0 in
let full_m1 = Map.upd full_m0 key full_v1 in
assert (p'.refine full_m1);
compatible_pointwise_upd p v1 full_v1 m0 full_m0 key;
assert (
let m1 = Map.upd m0 key v1 in
compatible p' m1 full_m1
);
lift_frame_preservation p m0 full_m0 v1 full_v1 key;
full_m1 | {
"file_name": "lib/steel/Steel.PCMMap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 302,
"start_col": 0,
"start_line": 280
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
module Steel.PCMMap
(** Given a PCM on [p:pcm a] and a key type [k:eqtype], this module
builds a [pcm (map k a)] by lifting [p] pointwise. It also lifts
frame-preserving updates on [p] to frame-preserving updates on
entries of the map. **)
open FStar.Map
open FStar.PCM
/// The carrier type of our constructed PCM
///
/// -- FStar.Map comes with a notion of domain that we don't need here
/// So, we'll just worked with maps whose domain is always
/// universal.
let map (k:eqtype) (v:Type) =
m:Map.t k v {
Map.domain m `Set.equal` Set.complement Set.empty
}
/// Maps are composable if they are composable pointwise
let composable_maps (#a:_)
(#k:eqtype)
(p:pcm a)
(m0 m1: map k a)
: prop
= forall k. Map.sel m0 k `composable p` Map.sel m1 k
/// Compose maps pointwise
let compose_maps (#a:_) (#k:eqtype)
(p:pcm a)
(m0:map k a)
(m1:map k a { composable_maps p m0 m1 })
: map k a
= Map.map_literal (fun k ->
Map.sel m0 k `op p` Map.sel m1 k)
/// Composability is commutative
let composable_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma (composable_maps p m0 m1 <==>
composable_maps p m1 m0)
= ()
/// Composition is commutative
let compose_maps_comm #k #a
(p:pcm a)
(m0 m1: map k a)
: Lemma
(requires composable_maps p m0 m1)
(ensures compose_maps p m0 m1 == compose_maps p m1 m0)
= let m01 = compose_maps p m0 m1 in
let m10 = compose_maps p m1 m0 in
introduce forall key.
Map.sel m01 key == Map.sel m10 key
with ( p.comm (Map.sel m0 key) (Map.sel m1 key) );
assert (Map.equal m01 m10)
/// Composability is left-associative
let composable_maps_assoc_l #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2))
(ensures
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2 /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m0 key) (Map.sel m1 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m01 = compose_maps p m0 m1 in
introduce forall key.
composable p (Map.sel m01 key) (Map.sel m2 key)
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p m01 m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal
(compose_maps p (compose_maps p m0 m1) m2)
(compose_maps p m0 (compose_maps p m1 m2)))
/// Composability is right-associative
let composable_maps_assoc_r #k #a
(p:pcm a)
(m0 m1 m2: map k a)
: Lemma
(requires
composable_maps p m0 m1 /\
composable_maps p (compose_maps p m0 m1) m2)
(ensures
composable_maps p m1 m2 /\
composable_maps p m0 (compose_maps p m1 m2) /\
compose_maps p (compose_maps p m0 m1) m2 ==
compose_maps p m0 (compose_maps p m1 m2))
= introduce forall key.
composable p (Map.sel m1 key) (Map.sel m2 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m12 = compose_maps p m1 m2 in
introduce forall key.
composable p (Map.sel m0 key) (Map.sel m12 key)
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
let m012 = compose_maps p (compose_maps p m0 m1) m2 in
let m012' = compose_maps p m0 (compose_maps p m1 m2) in
introduce forall key.
Map.sel m012 key == Map.sel m012' key
with ( p.assoc_r (Map.sel m0 key) (Map.sel m1 key) (Map.sel m2 key) );
assert (Map.equal m012 m012')
/// The core of the constructed PCM
/// The unit is just the pointwise unit
let pcm'_map_of_pcm (#a:_) (k:eqtype) (p:pcm a)
: pcm' (map k a)
= {
composable = composable_maps p;
op = compose_maps p;
one = Map.const p.p.one
}
/// The unit is really a unit
let is_unit #k #a (p:pcm a) (m:map k a)
: Lemma (composable_maps p (Map.const p.p.one) m /\
compose_maps p (Map.const p.p.one) m `Map.equal` m /\
compose_maps p m (Map.const p.p.one) `Map.equal` m)
= introduce forall k. composable p p.p.one (Map.sel m k)
with (
p.is_unit (Map.sel m k)
);
introduce forall k. Map.sel (compose_maps p (Map.const p.p.one) m) k == Map.sel m k /\
Map.sel (compose_maps p m (Map.const p.p.one)) k == Map.sel m k
with (
p.is_unit (Map.sel m k);
p.comm p.p.one (Map.sel m k)
)
/// The main function of this module:
/// Given a [k] and [p:pcm a], lift it pointwise
let pointwise (#a:_) (k:eqtype) (p:pcm a)
: pcm (map k a)
= {
p = pcm'_map_of_pcm k p;
comm = (fun m0 m1 -> compose_maps_comm p m0 m1);
assoc = (fun m0 m1 m2 -> composable_maps_assoc_l p m0 m1 m2);
assoc_r = (fun m0 m1 m2 -> composable_maps_assoc_r p m0 m1 m2);
is_unit = (fun m -> is_unit p m);
refine = (fun m -> forall k. p.refine (Map.sel m k))
}
/// Now some constructions that allow us to lift frame-preserving updates
/// If a two maps are compatible, then they are also compatible pointwise
let compatible_pointwise #a #k
(p:pcm a)
(m0 m1:map k a)
: Lemma
(requires compatible (pointwise k p) m0 m1)
(ensures forall k. compatible p (Map.sel m0 k) (Map.sel m1 k))
= let pcm' = pointwise k p in
introduce forall k. compatible p (Map.sel m0 k) (Map.sel m1 k)
with (
eliminate exists frame.
composable pcm' m0 frame /\ op pcm' frame m0 == m1
returns _
with _. (
introduce exists (frame:a).
composable p
(Map.sel m0 k)
frame /\
op p frame (Map.sel m0 k) == Map.sel m1 k
with (Map.sel frame k)
and ()))
/// A very specific lemma for use in lifting frame-preserving updates
///
/// If two maps are compatible, then updating them at a key with
/// values that are compatible produces compatible maps
let compatible_pointwise_upd #a (#k:eqtype)
(p:pcm a)
(v1 full_v1:a)
(m0 full_m0:map k a)
(key:k)
: Lemma
(requires
compatible p v1 full_v1 /\
compatible (pointwise k p) m0 full_m0)
(ensures
compatible (pointwise k p) (Map.upd m0 key v1)
(Map.upd full_m0 key full_v1))
= compatible_pointwise p m0 full_m0;
assert (compatible p (Map.sel m0 key) (Map.sel full_m0 key));
let m1 = (Map.upd m0 key v1) in
let full_m1 = (Map.upd full_m0 key full_v1) in
let p' = pointwise k p in
eliminate exists (frame_m0:_). composable p' m0 frame_m0 /\ op p' frame_m0 m0 == full_m0
returns _
with _. (
eliminate exists (frame0:_). composable p v1 frame0 /\ op p frame0 v1 == full_v1
returns _
with _. (
introduce exists (frame:_).
composable p' m1 frame /\ op p' frame m1 == full_m1
with (Map.upd frame_m0 key frame0)
and (
let w = Map.upd frame_m0 key frame0 in
assert (Map.equal (compose_maps p w m1) full_m1)
)))
/// If any frame composes with [v0] to produce [full_v0]
/// can also be composed with [v1] to produce [full_v1]
///
/// Then any frame composable with a map contains [v0] yielding a map
/// containing [full_v0], is also composable with a map containing
/// [v1] yielding [full_v1] at that key.
let lift_frame_preservation #a (#k:eqtype) (p:pcm a)
(m0 full_m0:map k a)
(v1 full_v1:a)
(key:k)
: Lemma
(requires (
let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
(forall (frame:a{composable p v0 frame}). {:pattern composable p v0 frame}
composable p v1 frame /\
(op p v0 frame == full_v0 ==>
op p v1 frame == full_v1))))
(ensures (
let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
let p' = pointwise k p in
(forall (frame:_{composable p' m0 frame}).
composable p' m1 frame /\
(op p' m0 frame == full_m0 ==>
op p' m1 frame == full_m1))))
= let v0 = Map.sel m0 key in
let full_v0 = Map.sel full_m0 key in
let m1 = Map.upd m0 key v1 in
let full_m1 = Map.upd full_m0 key full_v1 in
let p' = pointwise k p in
introduce forall (frame:_{composable p' m0 frame}).
composable p' m1 frame /\
(op p' m0 frame == full_m0 ==>
op p' m1 frame == full_m1)
with (
introduce _ /\ _
with ()
and ( introduce _ ==> _
with _. (
assert (compose_maps p m1 frame `Map.equal` full_m1)
)
)
)
/// Lift a frame-preserving update from [v0] to [v1] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.PCMMap.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
v0: FStar.Ghost.erased a ->
v1: FStar.Ghost.erased a ->
f: FStar.PCM.frame_preserving_upd p (FStar.Ghost.reveal v0) (FStar.Ghost.reveal v1) ->
m0: FStar.Ghost.erased (Steel.PCMMap.map k a) ->
key: k{FStar.Map.sel (FStar.Ghost.reveal m0) key == FStar.Ghost.reveal v0}
-> FStar.PCM.frame_preserving_upd (Steel.PCMMap.pointwise k p)
(FStar.Ghost.reveal m0)
(FStar.Map.upd (FStar.Ghost.reveal m0) key (FStar.Ghost.reveal v1)) | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.PCM.pcm",
"FStar.Ghost.erased",
"FStar.PCM.frame_preserving_upd",
"FStar.Ghost.reveal",
"Steel.PCMMap.map",
"Prims.eq2",
"FStar.Map.sel",
"Prims.l_and",
"FStar.PCM.__proj__Mkpcm__item__refine",
"Steel.PCMMap.pointwise",
"FStar.PCM.compatible",
"Prims.unit",
"Steel.PCMMap.lift_frame_preservation",
"Prims._assert",
"FStar.Map.t",
"FStar.Map.upd",
"Steel.PCMMap.compatible_pointwise_upd",
"Prims.l_Forall",
"FStar.PCM.composable",
"Prims.l_imp",
"FStar.PCM.op",
"Steel.PCMMap.compatible_pointwise"
] | [] | false | false | false | false | false | let lift_frame_preserving_upd
#a
#k
(#p: pcm a)
(v0: Ghost.erased a)
(v1: Ghost.erased a)
(f: frame_preserving_upd p v0 v1)
(m0: Ghost.erased (map k a))
(key: k{Map.sel m0 key == Ghost.reveal v0})
: frame_preserving_upd (pointwise k p) m0 (Map.upd m0 key v1) =
| fun full_m0 ->
let p' = pointwise k p in
let full_v0 = Map.sel full_m0 key in
assert (compatible (pointwise _ p) m0 full_m0);
assert (p.refine full_v0);
compatible_pointwise #a #k p m0 full_m0;
assert (compatible p v0 full_v0);
let full_v1 = f full_v0 in
let full_m1 = Map.upd full_m0 key full_v1 in
assert (p'.refine full_m1);
compatible_pointwise_upd p v1 full_v1 m0 full_m0 key;
assert (let m1 = Map.upd m0 key v1 in
compatible p' m1 full_m1);
lift_frame_preservation p m0 full_m0 v1 full_v1 key;
full_m1 | false |
Hacl.Impl.RSAPSS.Padding.fst | Hacl.Impl.RSAPSS.Padding.get_m1Hash | val get_m1Hash:
a:Hash.hash_alg{S.hash_is_supported a}
-> saltLen:salt_len_t a
-> salt:lbuffer uint8 saltLen
-> msgLen:msg_len_t a
-> msg:lbuffer uint8 msgLen
-> hLen:size_t{v hLen == Hash.hash_length a}
-> m1Hash:lbuffer uint8 hLen ->
Stack unit
(requires fun h ->
live h salt /\ live h msg /\ live h m1Hash /\
disjoint msg salt /\ disjoint m1Hash msg /\ disjoint m1Hash salt)
(ensures fun h0 _ h1 -> modifies (loc m1Hash) h0 h1 /\
(let mHash = Hash.hash a (as_seq h0 msg) in
let m1Len = 8 + Hash.hash_length a + v saltLen in
let m1 = LSeq.create m1Len (u8 0) in
let m1 = LSeq.update_sub m1 8 (Hash.hash_length a) mHash in
let m1 = LSeq.update_sub m1 (8 + Hash.hash_length a) (v saltLen) (as_seq h0 salt) in
as_seq h1 m1Hash == Hash.hash a m1)) | val get_m1Hash:
a:Hash.hash_alg{S.hash_is_supported a}
-> saltLen:salt_len_t a
-> salt:lbuffer uint8 saltLen
-> msgLen:msg_len_t a
-> msg:lbuffer uint8 msgLen
-> hLen:size_t{v hLen == Hash.hash_length a}
-> m1Hash:lbuffer uint8 hLen ->
Stack unit
(requires fun h ->
live h salt /\ live h msg /\ live h m1Hash /\
disjoint msg salt /\ disjoint m1Hash msg /\ disjoint m1Hash salt)
(ensures fun h0 _ h1 -> modifies (loc m1Hash) h0 h1 /\
(let mHash = Hash.hash a (as_seq h0 msg) in
let m1Len = 8 + Hash.hash_length a + v saltLen in
let m1 = LSeq.create m1Len (u8 0) in
let m1 = LSeq.update_sub m1 8 (Hash.hash_length a) mHash in
let m1 = LSeq.update_sub m1 (8 + Hash.hash_length a) (v saltLen) (as_seq h0 salt) in
as_seq h1 m1Hash == Hash.hash a m1)) | let get_m1Hash a saltLen salt msgLen msg hLen m1Hash =
push_frame ();
//m1 = [8 * 0x00; mHash; salt]
let m1Len = 8ul +! hLen +! saltLen in
let m1 = create m1Len (u8 0) in
let h0 = ST.get () in
update_sub_f h0 m1 8ul hLen
(fun h -> Hash.hash a (as_seq h0 msg))
(fun _ -> hash a (sub m1 8ul hLen) msgLen msg);
update_sub m1 (8ul +! hLen) saltLen salt;
hash a m1Hash m1Len m1;
pop_frame() | {
"file_name": "code/rsapss/Hacl.Impl.RSAPSS.Padding.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 100,
"start_col": 0,
"start_line": 89
} | module Hacl.Impl.RSAPSS.Padding
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.RSAPSS.MGF
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Hash = Spec.Agile.Hash
module S = Spec.RSAPSS
module BD = Hacl.Bignum.Definitions
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let less_than_max_input_length = Spec.Hash.Definitions.less_than_max_input_length
inline_for_extraction noextract
let salt_len_t (a:Hash.fixed_len_alg) =
saltLen:size_t{8 + Hash.hash_length a + v saltLen <= max_size_t /\ (8 + Hash.hash_length a + v saltLen) `less_than_max_input_length` a}
inline_for_extraction noextract
let msg_len_t (a:Hash.fixed_len_alg) =
msgLen:size_t{v msgLen `less_than_max_input_length` a}
inline_for_extraction noextract
let em_len_t (a:Hash.fixed_len_alg) (saltLen:salt_len_t a) =
emBits:size_t{0 < v emBits /\ Hash.hash_length a + v saltLen + 2 <= S.blocks (v emBits) 8}
inline_for_extraction noextract
val xor_bytes:
len:size_t{v len > 0}
-> b1:lbuffer uint8 len
-> b2:lbuffer uint8 len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1) h0 h1 /\
as_seq h1 b1 == S.xor_bytes (as_seq h0 b1) (as_seq h0 b2))
let xor_bytes len b1 b2 =
map2T len b1 (fun x y -> x ^. y) b1 b2
inline_for_extraction noextract
val db_zero:
len:size_t{v len > 0}
-> db:lbuffer uint8 len
-> emBits:size_t ->
Stack unit
(requires fun h -> live h db)
(ensures fun h0 _ h1 -> modifies (loc db) h0 h1 /\
as_seq h1 db == S.db_zero #(v len) (as_seq h0 db) (v emBits))
let db_zero len db emBits =
let msBits = emBits %. 8ul in
if msBits >. 0ul then
db.(0ul) <- db.(0ul) &. (u8 0xff >>. (8ul -. msBits))
inline_for_extraction noextract
val get_m1Hash:
a:Hash.hash_alg{S.hash_is_supported a}
-> saltLen:salt_len_t a
-> salt:lbuffer uint8 saltLen
-> msgLen:msg_len_t a
-> msg:lbuffer uint8 msgLen
-> hLen:size_t{v hLen == Hash.hash_length a}
-> m1Hash:lbuffer uint8 hLen ->
Stack unit
(requires fun h ->
live h salt /\ live h msg /\ live h m1Hash /\
disjoint msg salt /\ disjoint m1Hash msg /\ disjoint m1Hash salt)
(ensures fun h0 _ h1 -> modifies (loc m1Hash) h0 h1 /\
(let mHash = Hash.hash a (as_seq h0 msg) in
let m1Len = 8 + Hash.hash_length a + v saltLen in
let m1 = LSeq.create m1Len (u8 0) in
let m1 = LSeq.update_sub m1 8 (Hash.hash_length a) mHash in
let m1 = LSeq.update_sub m1 (8 + Hash.hash_length a) (v saltLen) (as_seq h0 salt) in
as_seq h1 m1Hash == Hash.hash a m1)) | {
"checked_file": "/",
"dependencies": [
"Spec.RSAPSS.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.RSAPSS.MGF.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.RSAPSS.Padding.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Spec.RSAPSS",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS.MGF",
"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.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} ->
saltLen: Hacl.Impl.RSAPSS.Padding.salt_len_t a ->
salt: Lib.Buffer.lbuffer Lib.IntTypes.uint8 saltLen ->
msgLen: Hacl.Impl.RSAPSS.Padding.msg_len_t a ->
msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msgLen ->
hLen: Lib.IntTypes.size_t{Lib.IntTypes.v hLen == Spec.Hash.Definitions.hash_length a} ->
m1Hash: Lib.Buffer.lbuffer Lib.IntTypes.uint8 hLen
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Prims.b2t",
"Spec.RSAPSS.hash_is_supported",
"Hacl.Impl.RSAPSS.Padding.salt_len_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Impl.RSAPSS.Padding.msg_len_t",
"Lib.IntTypes.size_t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.max_size_t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Spec.Hash.Definitions.hash_length",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.RSAPSS.MGF.hash",
"Lib.Buffer.update_sub",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Plus_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.update_sub_f",
"FStar.Monotonic.HyperStack.mem",
"Spec.Agile.Hash.hash",
"Lib.Buffer.as_seq",
"Lib.Sequence.lseq",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Hacl.Impl.RSAPSS.MGF.hash_len",
"Lib.Buffer.sub",
"FStar.HyperStack.ST.get",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let get_m1Hash a saltLen salt msgLen msg hLen m1Hash =
| push_frame ();
let m1Len = 8ul +! hLen +! saltLen in
let m1 = create m1Len (u8 0) in
let h0 = ST.get () in
update_sub_f h0
m1
8ul
hLen
(fun h -> Hash.hash a (as_seq h0 msg))
(fun _ -> hash a (sub m1 8ul hLen) msgLen msg);
update_sub m1 (8ul +! hLen) saltLen salt;
hash a m1Hash m1Len m1;
pop_frame () | false |
Steel.ST.BitVector.fst | Steel.ST.BitVector.pts_to_length | val pts_to_length (#opened:_) (#n:US.t) (#p:perm) (bv:bv_t n) (s:repr)
: STGhost unit opened
(pts_to bv p s)
(fun _ -> pts_to bv p s)
(requires True)
(ensures fun _ -> Seq.length s == US.v n) | val pts_to_length (#opened:_) (#n:US.t) (#p:perm) (bv:bv_t n) (s:repr)
: STGhost unit opened
(pts_to bv p s)
(fun _ -> pts_to bv p s)
(requires True)
(ensures fun _ -> Seq.length s == US.v n) | let pts_to_length bv s = A.pts_to_length bv s | {
"file_name": "lib/steel/Steel.ST.BitVector.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 45,
"end_line": 35,
"start_col": 0,
"start_line": 35
} | (*
Copyright 2021 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.
Authors: Aseem Rastogi
*)
module Steel.ST.BitVector
open Steel.ST.Effect.Ghost
open Steel.ST.Effect
open Steel.ST.Util
module US = FStar.SizeT
module G = FStar.Ghost
module A = Steel.ST.Array
/// Implementation of bv_t using an array of bool
type bv_t n = a:A.array bool{A.length a == US.v n /\ A.is_full_array a}
let pts_to bv p s = A.pts_to bv p s | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Effect.Ghost.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.BitVector.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | bv: Steel.ST.BitVector.bv_t n -> s: Steel.ST.BitVector.repr
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"FStar.SizeT.t",
"Steel.FractionalPermission.perm",
"Steel.ST.BitVector.bv_t",
"Steel.ST.BitVector.repr",
"Steel.ST.Array.pts_to_length",
"Prims.bool",
"Prims.unit"
] | [] | false | true | false | false | false | let pts_to_length bv s =
| A.pts_to_length bv s | false |
Steel.ST.BitVector.fst | Steel.ST.BitVector.bv_is_set | val bv_is_set
(#n:US.t)
(#p:perm)
(#s:G.erased repr)
(bv:bv_t n)
(i:US.t{US.v i < Seq.length s})
: ST bool
(pts_to bv p s)
(fun _ -> pts_to bv p s)
(requires True)
(ensures fun b -> b == Seq.index s (US.v i)) | val bv_is_set
(#n:US.t)
(#p:perm)
(#s:G.erased repr)
(bv:bv_t n)
(i:US.t{US.v i < Seq.length s})
: ST bool
(pts_to bv p s)
(fun _ -> pts_to bv p s)
(requires True)
(ensures fun b -> b == Seq.index s (US.v i)) | let bv_is_set bv i = A.read bv i | {
"file_name": "lib/steel/Steel.ST.BitVector.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 32,
"end_line": 39,
"start_col": 0,
"start_line": 39
} | (*
Copyright 2021 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.
Authors: Aseem Rastogi
*)
module Steel.ST.BitVector
open Steel.ST.Effect.Ghost
open Steel.ST.Effect
open Steel.ST.Util
module US = FStar.SizeT
module G = FStar.Ghost
module A = Steel.ST.Array
/// Implementation of bv_t using an array of bool
type bv_t n = a:A.array bool{A.length a == US.v n /\ A.is_full_array a}
let pts_to bv p s = A.pts_to bv p s
let pts_to_length bv s = A.pts_to_length bv s
let alloc n = A.alloc false n | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Effect.Ghost.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.BitVector.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bv: Steel.ST.BitVector.bv_t n ->
i: FStar.SizeT.t{FStar.SizeT.v i < FStar.Seq.Base.length (FStar.Ghost.reveal s)}
-> Steel.ST.Effect.ST Prims.bool | Steel.ST.Effect.ST | [] | [] | [
"FStar.SizeT.t",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.ST.BitVector.repr",
"Steel.ST.BitVector.bv_t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.SizeT.v",
"FStar.Seq.Base.length",
"Prims.bool",
"FStar.Ghost.reveal",
"Steel.ST.Array.read"
] | [] | false | true | false | false | false | let bv_is_set bv i =
| A.read bv i | false |
Hacl.Impl.P256.PointAdd.fst | Hacl.Impl.P256.PointAdd.point_add_noalloc | val point_add_noalloc: tmp:lbuffer uint64 24ul -> res:point -> p:point -> q:point -> Stack unit
(requires fun h ->
live h p /\ live h q /\ live h res /\ live h tmp /\
eq_or_disjoint p q /\ disjoint q res /\ disjoint p res /\
disjoint tmp p /\ disjoint tmp q /\ disjoint tmp res /\
point_inv h p /\ point_inv h q)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
point_inv h1 res /\
from_mont_point (as_point_nat h1 res) ==
S.point_add (from_mont_point (as_point_nat h0 p)) (from_mont_point (as_point_nat h0 q))) | val point_add_noalloc: tmp:lbuffer uint64 24ul -> res:point -> p:point -> q:point -> Stack unit
(requires fun h ->
live h p /\ live h q /\ live h res /\ live h tmp /\
eq_or_disjoint p q /\ disjoint q res /\ disjoint p res /\
disjoint tmp p /\ disjoint tmp q /\ disjoint tmp res /\
point_inv h p /\ point_inv h q)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
point_inv h1 res /\
from_mont_point (as_point_nat h1 res) ==
S.point_add (from_mont_point (as_point_nat h0 p)) (from_mont_point (as_point_nat h0 q))) | let point_add_noalloc tmp res p q =
let x3, y3, z3 = getx res, gety res, getz res in
let t0 = sub tmp 0ul 4ul in
let t1 = sub tmp 4ul 4ul in
let t2 = sub tmp 8ul 4ul in
let t3 = sub tmp 12ul 4ul in
let t4 = sub tmp 16ul 4ul in
let t5 = sub tmp 20ul 4ul in
point_add_1 t0 t1 t2 t3 t4 p q;
point_add_2 t1 t2 t3 t4 t5 p q;
point_add_3 x3 y3 t0 t2 p q;
point_add_4 x3 y3 z3 t1 t2;
point_add_5 x3 y3 z3 t0 t1 t2;
point_add_6 x3 y3 z3 t0 t1 t2 t4;
point_add_7 x3 y3 z3 t0 t1 t2 t3 t4 | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.PointAdd.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 297,
"start_col": 0,
"start_line": 283
} | module Hacl.Impl.P256.PointAdd
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
module ST = FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
open Hacl.Impl.P256.Field
module S = Spec.P256
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val point_add_1 (t0 t1 t2 t3 t4:felem) (p q:point) : Stack unit
(requires fun h ->
live h t0 /\ live h t1 /\ live h t2 /\
live h t3 /\ live h t4 /\ live h p /\ live h q /\
LowStar.Monotonic.Buffer.all_disjoint
[loc t0; loc t1; loc t2; loc t3; loc t4 ] /\
eq_or_disjoint p q /\ disjoint p t0 /\ disjoint p t1 /\
disjoint p t2 /\ disjoint p t3 /\ disjoint p t4 /\
disjoint q t0 /\ disjoint q t1 /\ disjoint q t2 /\
disjoint q t3 /\ disjoint q t4 /\
point_inv h p /\ point_inv h q)
(ensures fun h0 _ h1 -> modifies (loc t0 |+| loc t1 |+| loc t2 |+| loc t3 |+| loc t4) h0 h1 /\
as_nat h1 t0 < S.prime /\ as_nat h1 t1 < S.prime /\
as_nat h1 t2 < S.prime /\ as_nat h1 t3 < S.prime /\
as_nat h1 t4 < S.prime /\
(let x1, y1, z1 = from_mont_point (as_point_nat h0 p) in
let x2, y2, z2 = from_mont_point (as_point_nat h0 q) in
let t0_s = S.fmul x1 x2 in
let t1_s = S.fmul y1 y2 in
let t2_s = S.fmul z1 z2 in
let t3_s = S.fadd x1 y1 in
let t4_s = S.fadd x2 y2 in
let t3_s = S.fmul t3_s t4_s in
let t4_s = S.fadd t0_s t1_s in
fmont_as_nat h1 t0 == t0_s /\ fmont_as_nat h1 t1 == t1_s /\
fmont_as_nat h1 t2 == t2_s /\ fmont_as_nat h1 t3 == t3_s /\
fmont_as_nat h1 t4 == t4_s))
let point_add_1 t0 t1 t2 t3 t4 p q =
let x1, y1, z1 = getx p, gety p, getz p in
let x2, y2, z2 = getx q, gety q, getz q in
fmul t0 x1 x2;
fmul t1 y1 y2;
fmul t2 z1 z2;
fadd t3 x1 y1;
fadd t4 x2 y2;
fmul t3 t3 t4;
fadd t4 t0 t1
inline_for_extraction noextract
val point_add_2 (t1 t2 t3 t4 t5:felem) (p q:point) : Stack unit
(requires fun h ->
live h t1 /\ live h t2 /\ live h t3 /\ live h t4 /\ live h t5 /\
live h p /\ live h q /\
LowStar.Monotonic.Buffer.all_disjoint [ loc t1; loc t2; loc t3; loc t4; loc t5 ] /\
eq_or_disjoint p q /\ disjoint p t1 /\ disjoint p t2 /\
disjoint p t3 /\ disjoint p t4 /\ disjoint p t5 /\
disjoint q t1 /\ disjoint q t2 /\ disjoint q t3 /\
disjoint q t4 /\ disjoint q t5 /\
point_inv h p /\ point_inv h q /\
as_nat h t1 < S.prime /\ as_nat h t2 < S.prime /\
as_nat h t3 < S.prime /\ as_nat h t4 < S.prime)
(ensures fun h0 _ h1 -> modifies (loc t3 |+| loc t4 |+| loc t5) h0 h1 /\
as_nat h1 t3 < S.prime /\ as_nat h1 t4 < S.prime /\ as_nat h1 t5 < S.prime /\
(let x1, y1, z1 = from_mont_point (as_point_nat h0 p) in
let x2, y2, z2 = from_mont_point (as_point_nat h0 q) in
let t1_s = fmont_as_nat h0 t1 in
let t2_s = fmont_as_nat h0 t2 in
let t3_s = fmont_as_nat h0 t3 in
let t4_s = fmont_as_nat h0 t4 in
let t3_s = S.fsub t3_s t4_s in
let t4_s = S.fadd y1 z1 in
let t5_s = S.fadd y2 z2 in
let t4_s = S.fmul t4_s t5_s in
let t5_s = S.fadd t1_s t2_s in
let t4_s = S.fsub t4_s t5_s in
fmont_as_nat h1 t3 == t3_s /\ fmont_as_nat h1 t4 == t4_s /\
fmont_as_nat h1 t5 == t5_s))
let point_add_2 t1 t2 t3 t4 t5 p q =
let y1, z1 = gety p, getz p in
let y2, z2 = gety q, getz q in
fsub t3 t3 t4;
fadd t4 y1 z1;
fadd t5 y2 z2;
fmul t4 t4 t5;
fadd t5 t1 t2;
fsub t4 t4 t5
inline_for_extraction noextract
val point_add_3 (x3 y3 t0 t2:felem) (p q:point) : Stack unit
(requires fun h ->
live h x3 /\ live h y3 /\ live h t0 /\ live h t2 /\
live h p /\ live h q /\
LowStar.Monotonic.Buffer.all_disjoint [ loc x3; loc y3; loc t0; loc t2 ] /\
eq_or_disjoint p q /\ disjoint p x3 /\ disjoint p y3 /\
disjoint p t0 /\ disjoint p t2 /\ disjoint q x3 /\
disjoint q y3 /\ disjoint q t0 /\ disjoint q t2 /\
point_inv h p /\ point_inv h q /\
as_nat h t0 < S.prime /\ as_nat h t2 < S.prime)
(ensures fun h0 _ h1 -> modifies (loc x3 |+| loc y3) h0 h1 /\
as_nat h1 x3 < S.prime /\ as_nat h1 y3 < S.prime /\
(let x1, y1, z1 = from_mont_point (as_point_nat h0 p) in
let x2, y2, z2 = from_mont_point (as_point_nat h0 q) in
let t0_s = fmont_as_nat h0 t0 in
let t2_s = fmont_as_nat h0 t2 in
let x3_s = S.fadd x1 z1 in
let y3_s = S.fadd x2 z2 in
let x3_s = S.fmul x3_s y3_s in
let y3_s = S.fadd t0_s t2_s in
let y3_s = S.fsub x3_s y3_s in
fmont_as_nat h1 x3 == x3_s /\ fmont_as_nat h1 y3 == y3_s))
let point_add_3 x3 y3 t0 t2 p q =
let x1, z1 = getx p, getz p in
let x2, z2 = getx q, getz q in
fadd x3 x1 z1;
fadd y3 x2 z2;
fmul x3 x3 y3;
fadd y3 t0 t2;
fsub y3 x3 y3
inline_for_extraction noextract
val point_add_4 (x3 y3 z3 t1 t2:felem) : Stack unit
(requires fun h ->
live h x3 /\ live h y3 /\ live h z3 /\ live h t1 /\ live h t2 /\
LowStar.Monotonic.Buffer.all_disjoint [ loc x3; loc y3; loc z3; loc t1; loc t2 ] /\
as_nat h t1 < S.prime /\ as_nat h t2 < S.prime /\ as_nat h y3 < S.prime)
(ensures fun h0 _ h1 -> modifies (loc x3 |+| loc y3 |+| loc z3) h0 h1 /\
as_nat h1 x3 < S.prime /\ as_nat h1 y3 < S.prime /\ as_nat h1 z3 < S.prime /\
(let t1_s = fmont_as_nat h0 t1 in
let t2_s = fmont_as_nat h0 t2 in
let y3_s = fmont_as_nat h0 y3 in
let z3_s = S.fmul S.b_coeff t2_s in
let x3_s = S.fsub y3_s z3_s in
let z3_s = S.fadd x3_s x3_s in
let x3_s = S.fadd x3_s z3_s in
let z3_s = S.fsub t1_s x3_s in
let x3_s = S.fadd t1_s x3_s in
let y3_s = S.fmul S.b_coeff y3_s in
fmont_as_nat h1 x3 == x3_s /\ fmont_as_nat h1 y3 == y3_s /\ fmont_as_nat h1 z3 == z3_s))
let point_add_4 x3 y3 z3 t1 t2 =
fmul_by_b_coeff z3 t2;
fsub x3 y3 z3;
fdouble z3 x3;
fadd x3 x3 z3;
fsub z3 t1 x3;
fadd x3 t1 x3;
fmul_by_b_coeff y3 y3
inline_for_extraction noextract
val point_add_5 (x3 y3 z3 t0 t1 t2:felem) : Stack unit
(requires fun h ->
live h x3 /\ live h y3 /\ live h z3 /\
live h t0 /\ live h t1 /\ live h t2 /\
LowStar.Monotonic.Buffer.all_disjoint [ loc x3; loc y3; loc z3; loc t0; loc t1; loc t2 ] /\
as_nat h y3 < S.prime /\ as_nat h t0 < S.prime /\
as_nat h t1 < S.prime /\ as_nat h t2 < S.prime)
(ensures fun h0 _ h1 -> modifies (loc y3 |+| loc t1 |+| loc t2) h0 h1 /\
as_nat h1 t1 < S.prime /\ as_nat h1 t2 < S.prime /\ as_nat h1 y3 < S.prime /\
(let t0_s = fmont_as_nat h0 t0 in
let t1_s = fmont_as_nat h0 t1 in
let t2_s = fmont_as_nat h0 t2 in
let y3_s = fmont_as_nat h0 y3 in
let t1_s = S.fadd t2_s t2_s in
let t2_s = S.fadd t1_s t2_s in
let y3_s = S.fsub y3_s t2_s in
let y3_s = S.fsub y3_s t0_s in
let t1_s = S.fadd y3_s y3_s in
fmont_as_nat h1 t1 == t1_s /\ fmont_as_nat h1 t2 == t2_s /\ fmont_as_nat h1 y3 == y3_s))
let point_add_5 x3 y3 z3 t0 t1 t2 =
fdouble t1 t2;
fadd t2 t1 t2;
fsub y3 y3 t2;
fsub y3 y3 t0;
fdouble t1 y3
inline_for_extraction noextract
val point_add_6 (x3 y3 z3 t0 t1 t2 t4:felem) : Stack unit
(requires fun h ->
live h x3 /\ live h y3 /\ live h z3 /\
live h t0 /\ live h t1 /\ live h t2 /\ live h t4 /\
LowStar.Monotonic.Buffer.all_disjoint
[ loc x3; loc y3; loc z3; loc t0; loc t1; loc t2; loc t4 ] /\
as_nat h y3 < S.prime /\ as_nat h t0 < S.prime /\
as_nat h t1 < S.prime /\ as_nat h t2 < S.prime /\
as_nat h t4 < S.prime)
(ensures fun h0 _ h1 -> modifies (loc y3 |+| loc t0 |+| loc t1 |+| loc t2) h0 h1 /\
as_nat h1 t0 < S.prime /\ as_nat h1 t1 < S.prime /\
as_nat h1 t2 < S.prime /\ as_nat h1 y3 < S.prime /\
(let t0_s = fmont_as_nat h0 t0 in
let t1_s = fmont_as_nat h0 t1 in
let t2_s = fmont_as_nat h0 t2 in
let t4_s = fmont_as_nat h0 t4 in
let y3_s = fmont_as_nat h0 y3 in
let y3_s = S.fadd t1_s y3_s in
let t1_s = S.fadd t0_s t0_s in
let t0_s = S.fadd t1_s t0_s in
let t0_s = S.fsub t0_s t2_s in
let t1_s = S.fmul t4_s y3_s in
let t2_s = S.fmul t0_s y3_s in
fmont_as_nat h1 t0 == t0_s /\ fmont_as_nat h1 t1 == t1_s /\
fmont_as_nat h1 t2 == t2_s /\ fmont_as_nat h1 y3 == y3_s))
let point_add_6 x3 y3 z3 t0 t1 t2 t4 =
fadd y3 t1 y3;
fdouble t1 t0;
fadd t0 t1 t0;
fsub t0 t0 t2;
fmul t1 t4 y3;
fmul t2 t0 y3
inline_for_extraction noextract
val point_add_7 (x3 y3 z3 t0 t1 t2 t3 t4:felem) : Stack unit
(requires fun h ->
live h x3 /\ live h y3 /\ live h z3 /\
live h t0 /\ live h t1 /\ live h t2 /\ live h t3 /\ live h t4 /\
LowStar.Monotonic.Buffer.all_disjoint
[ loc x3; loc y3; loc z3; loc t0; loc t1; loc t2; loc t3; loc t4 ] /\
as_nat h x3 < S.prime /\ as_nat h z3 < S.prime /\
as_nat h t0 < S.prime /\ as_nat h t1 < S.prime /\
as_nat h t2 < S.prime /\ as_nat h t3 < S.prime /\ as_nat h t4 < S.prime)
(ensures fun h0 _ h1 -> modifies (loc x3 |+| loc y3 |+| loc z3 |+| loc t1) h0 h1 /\
as_nat h1 x3 < S.prime /\ as_nat h1 y3 < S.prime /\
as_nat h1 z3 < S.prime /\ as_nat h1 t1 < S.prime /\
(let x3_s = fmont_as_nat h0 x3 in
let z3_s = fmont_as_nat h0 z3 in
let t0_s = fmont_as_nat h0 t0 in
let t1_s = fmont_as_nat h0 t1 in
let t2_s = fmont_as_nat h0 t2 in
let t3_s = fmont_as_nat h0 t3 in
let t4_s = fmont_as_nat h0 t4 in
let y3_s = S.fmul x3_s z3_s in
let y3_s = S.fadd y3_s t2_s in
let x3_s = S.fmul t3_s x3_s in
let x3_s = S.fsub x3_s t1_s in
let z3_s = S.fmul t4_s z3_s in
let t1_s = S.fmul t3_s t0_s in
let z3_s = S.fadd z3_s t1_s in
fmont_as_nat h1 x3 == x3_s /\ fmont_as_nat h1 y3 == y3_s /\
fmont_as_nat h1 z3 == z3_s /\ fmont_as_nat h1 t1 == t1_s))
let point_add_7 x3 y3 z3 t0 t1 t2 t3 t4 =
fmul y3 x3 z3;
fadd y3 y3 t2;
fmul x3 t3 x3;
fsub x3 x3 t1;
fmul z3 t4 z3;
fmul t1 t3 t0;
fadd z3 z3 t1
inline_for_extraction noextract
val point_add_noalloc: tmp:lbuffer uint64 24ul -> res:point -> p:point -> q:point -> Stack unit
(requires fun h ->
live h p /\ live h q /\ live h res /\ live h tmp /\
eq_or_disjoint p q /\ disjoint q res /\ disjoint p res /\
disjoint tmp p /\ disjoint tmp q /\ disjoint tmp res /\
point_inv h p /\ point_inv h q)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
point_inv h1 res /\
from_mont_point (as_point_nat h1 res) ==
S.point_add (from_mont_point (as_point_nat h0 p)) (from_mont_point (as_point_nat h0 q))) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.Field.fsti.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.P256.PointAdd.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Field",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
tmp: Lib.Buffer.lbuffer Lib.IntTypes.uint64 24ul ->
res: Hacl.Impl.P256.Point.point ->
p: Hacl.Impl.P256.Point.point ->
q: Hacl.Impl.P256.Point.point
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.P256.Point.point",
"Hacl.Impl.P256.Bignum.felem",
"Hacl.Impl.P256.PointAdd.point_add_7",
"Prims.unit",
"Hacl.Impl.P256.PointAdd.point_add_6",
"Hacl.Impl.P256.PointAdd.point_add_5",
"Hacl.Impl.P256.PointAdd.point_add_4",
"Hacl.Impl.P256.PointAdd.point_add_3",
"Hacl.Impl.P256.PointAdd.point_add_2",
"Hacl.Impl.P256.PointAdd.point_add_1",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Hacl.Impl.P256.Point.getz",
"Hacl.Impl.P256.Point.gety",
"Hacl.Impl.P256.Point.getx"
] | [] | false | true | false | false | false | let point_add_noalloc tmp res p q =
| let x3, y3, z3 = getx res, gety res, getz res in
let t0 = sub tmp 0ul 4ul in
let t1 = sub tmp 4ul 4ul in
let t2 = sub tmp 8ul 4ul in
let t3 = sub tmp 12ul 4ul in
let t4 = sub tmp 16ul 4ul in
let t5 = sub tmp 20ul 4ul in
point_add_1 t0 t1 t2 t3 t4 p q;
point_add_2 t1 t2 t3 t4 t5 p q;
point_add_3 x3 y3 t0 t2 p q;
point_add_4 x3 y3 z3 t1 t2;
point_add_5 x3 y3 z3 t0 t1 t2;
point_add_6 x3 y3 z3 t0 t1 t2 t4;
point_add_7 x3 y3 z3 t0 t1 t2 t3 t4 | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.parse_bounded_vlgen_kind | val parse_bounded_vlgen_kind : sk: LowParse.Spec.Base.parser_kind ->
min: Prims.nat ->
max: Prims.nat{min <= max} ->
k: LowParse.Spec.Base.parser_kind
-> LowParse.Spec.Base.parser_kind | let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k) | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 63,
"end_line": 117,
"start_col": 0,
"start_line": 112
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
sk: LowParse.Spec.Base.parser_kind ->
min: Prims.nat ->
max: Prims.nat{min <= max} ->
k: LowParse.Spec.Base.parser_kind
-> LowParse.Spec.Base.parser_kind | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.VLGen.parse_bounded_vlgen_payload_kind"
] | [] | false | false | false | false | false | let parse_bounded_vlgen_kind (sk: parser_kind) (min: nat) (max: nat{min <= max}) (k: parser_kind) =
| and_then_kind sk (parse_bounded_vlgen_payload_kind min max k) | false |
|
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.synth_vlgen | val synth_vlgen
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t | val synth_vlgen
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t | let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 223,
"start_col": 0,
"start_line": 214
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat ->
s: LowParse.Spec.Base.serializer p ->
x: LowParse.Spec.VLData.parse_bounded_vldata_strong_t min max s
-> t | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t"
] | [] | false | false | false | false | false | let synth_vlgen
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t =
| x | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.pattern_to_string | val pattern_to_string (p:pattern) : T.Tac string | val pattern_to_string (p:pattern) : T.Tac string | let rec st_term_to_string' (level:string) (t:st_term)
: T.Tac string
= match t.term with
| Tm_Return { insert_eq; term } ->
sprintf "return_%s %s"
(if insert_eq then "" else "_noeq")
(term_to_string term)
| Tm_STApp {head; arg_qual; arg } ->
sprintf "(%s%s %s%s)"
(if dbg_printing then "<stapp>" else "")
(term_to_string head)
(qual_to_string arg_qual)
(term_to_string arg)
| Tm_Bind { binder; head; body } ->
// if T.unseal binder.binder_ppname.name = "_"
// then sprintf "%s;\n%s%s"
// (st_term_to_string' level head)
// level
// (st_term_to_string' level body)
// else (
sprintf "let %s = %s;\n%s%s"
(binder_to_string binder)
(st_term_to_string' level head)
level
(st_term_to_string' level body)
// )
| Tm_TotBind { head; binder; body } ->
sprintf "let tot %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string head)
level
(st_term_to_string' level body)
| Tm_Abs { b; q; ascription=c; body } ->
sprintf "(fun (%s%s)\n%s\n ({\n%s%s\n}%s)"
(qual_to_string q)
(binder_to_string b)
(match c.annotated with | None -> "" | Some c -> comp_to_string c)
(indent level)
(st_term_to_string' (indent level) body)
(match c.elaborated with | None -> "" | Some c -> " <: " ^ comp_to_string c)
| Tm_If { b; then_; else_ } ->
sprintf "if (%s)\n%s{\n%s%s\n%s}\n%selse\n%s{\n%s%s\n%s}"
(term_to_string b)
level
(indent level)
(st_term_to_string' (indent level) then_)
level
level
level
(indent level)
(st_term_to_string' (indent level) else_)
level
| Tm_Match {sc; brs} ->
sprintf "match (%s) with %s"
(term_to_string sc)
(branches_to_string brs)
| Tm_IntroPure { p } ->
sprintf "introduce pure (\n%s%s)"
(indent level)
(term_to_string' (indent level) p)
| Tm_ElimExists { p } ->
sprintf "elim_exists %s"
(term_to_string p)
| Tm_IntroExists { p; witnesses } ->
sprintf "introduce\n%s%s\n%swith %s"
(indent level)
(term_to_string' (indent level) p)
level
(term_list_to_string " " witnesses)
| Tm_While { invariant; condition; body } ->
sprintf "while (%s)\n%sinvariant %s\n%s{\n%s%s\n%s}"
(st_term_to_string' level condition)
level
(term_to_string invariant)
level
(indent level)
(st_term_to_string' (indent level) body)
level
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
sprintf "par (<%s> (%s) <%s) (<%s> (%s) <%s)"
(term_to_string pre1)
(st_term_to_string' level body1)
(term_to_string post1)
(term_to_string pre2)
(st_term_to_string' level body2)
(term_to_string post2)
| Tm_Rewrite { t1; t2 } ->
sprintf "rewrite %s %s"
(term_to_string t1)
(term_to_string t2)
| Tm_WithLocal { binder; initializer; body } ->
sprintf "let mut %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
level
(st_term_to_string' level body)
| Tm_WithLocalArray { binder; initializer; length; body } ->
sprintf "let mut %s = [| %s; %s |]\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
(term_to_string length)
level
(st_term_to_string' level body)
| Tm_Admit { ctag; u; typ; post } ->
sprintf "%s<%s> %s%s"
(match ctag with
| STT -> "stt_admit"
| STT_Atomic -> "stt_atomic_admit"
| STT_Ghost -> "stt_ghost_admit")
(universe_to_string 0 u)
(term_to_string typ)
(match post with
| None -> ""
| Some post -> sprintf " %s" (term_to_string post))
| Tm_Unreachable -> "unreachable ()"
| Tm_ProofHintWithBinders { binders; hint_type; t} ->
let with_prefix =
match binders with
| [] -> ""
| _ -> sprintf "with %s." (String.concat " " (T.map binder_to_string binders))
in
let names_to_string = function
| None -> ""
| Some l -> sprintf " [%s]" (String.concat "; " l)
in
let ht, p =
match hint_type with
| ASSERT { p } -> "assert", term_to_string p
| UNFOLD { names; p } -> sprintf "unfold%s" (names_to_string names), term_to_string p
| FOLD { names; p } -> sprintf "fold%s" (names_to_string names), term_to_string p
| RENAME { pairs; goal } ->
sprintf "rewrite each %s"
(String.concat ", "
(T.map
(fun (x, y) -> sprintf "%s as %s" (term_to_string x) (term_to_string y))
pairs)),
(match goal with
| None -> ""
| Some t -> sprintf " in %s" (term_to_string t))
| REWRITE { t1; t2 } ->
sprintf "rewrite %s as %s" (term_to_string t1) (term_to_string t2), ""
| WILD -> "_", ""
| SHOW_PROOF_STATE _ -> "show_proof_state", ""
in
sprintf "%s %s %s; %s" with_prefix ht p
(st_term_to_string' level t)
| Tm_WithInv { name; body; returns_inv } ->
sprintf "with_inv %s %s %s"
(term_to_string name)
(st_term_to_string' level body)
(match returns_inv with
| None -> ""
| Some (b, t) ->
sprintf "\nreturns %s\nensures %s"
(binder_to_string b)
(term_to_string t))
and branches_to_string brs : T.Tac _ =
match brs with
| [] -> ""
| b::bs -> branch_to_string b ^ branches_to_string bs
and branch_to_string br : T.Tac _ =
let (pat, e) = br in
Printf.sprintf "{ %s -> %s }"
(pattern_to_string pat)
(st_term_to_string' "" e)
and pattern_to_string (p:pattern) : T.Tac string =
match p with
| Pat_Cons fv pats ->
Printf.sprintf "(%s %s)"
(String.concat "." fv.fv_name)
(String.concat " " (T.map (fun (p, _) -> pattern_to_string p) pats))
| Pat_Constant c ->
"<constant>"
| Pat_Var x _ ->
T.unseal x
| Pat_Dot_Term None ->
""
| Pat_Dot_Term (Some t) ->
Printf.sprintf "(.??)" | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 26,
"end_line": 428,
"start_col": 0,
"start_line": 229
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral"
let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens)
let comp_to_string (c:comp)
: T.Tac string
= match c with
| C_Tot t ->
sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
let term_opt_to_string (t:option term)
: T.Tac string
= match t with
| None -> ""
| Some t -> term_to_string t
let term_list_to_string (sep:string) (t:list term)
: T.Tac string
= String.concat sep (T.map term_to_string t) | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Pulse.Syntax.Base.pattern -> FStar.Tactics.Effect.Tac Prims.string | FStar.Tactics.Effect.Tac | [] | [
"st_term_to_string'",
"branches_to_string",
"branch_to_string",
"pattern_to_string"
] | [
"Pulse.Syntax.Base.pattern",
"Pulse.Syntax.Base.fv",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.bool",
"FStar.Printf.sprintf",
"FStar.String.concat",
"Pulse.Syntax.Base.__proj__Mkfv__item__fv_name",
"Prims.string",
"FStar.Tactics.Util.map",
"Pulse.Syntax.Printer.pattern_to_string",
"Pulse.Syntax.Base.constant",
"FStar.Reflection.Typing.pp_name_t",
"FStar.Reflection.Typing.sort_t",
"FStar.Tactics.Unseal.unseal",
"Pulse.Syntax.Base.term"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec pattern_to_string (p: pattern) : T.Tac string =
| match p with
| Pat_Cons fv pats ->
Printf.sprintf "(%s %s)"
(String.concat "." fv.fv_name)
(String.concat " " (T.map (fun (p, _) -> pattern_to_string p) pats))
| Pat_Constant c -> "<constant>"
| Pat_Var x _ -> T.unseal x
| Pat_Dot_Term None -> ""
| Pat_Dot_Term (Some t) -> Printf.sprintf "(.??)" | false |
Pulse.Syntax.Printer.fst | Pulse.Syntax.Printer.st_term_to_string' | val st_term_to_string' (level: string) (t: st_term) : T.Tac string | val st_term_to_string' (level: string) (t: st_term) : T.Tac string | let rec st_term_to_string' (level:string) (t:st_term)
: T.Tac string
= match t.term with
| Tm_Return { insert_eq; term } ->
sprintf "return_%s %s"
(if insert_eq then "" else "_noeq")
(term_to_string term)
| Tm_STApp {head; arg_qual; arg } ->
sprintf "(%s%s %s%s)"
(if dbg_printing then "<stapp>" else "")
(term_to_string head)
(qual_to_string arg_qual)
(term_to_string arg)
| Tm_Bind { binder; head; body } ->
// if T.unseal binder.binder_ppname.name = "_"
// then sprintf "%s;\n%s%s"
// (st_term_to_string' level head)
// level
// (st_term_to_string' level body)
// else (
sprintf "let %s = %s;\n%s%s"
(binder_to_string binder)
(st_term_to_string' level head)
level
(st_term_to_string' level body)
// )
| Tm_TotBind { head; binder; body } ->
sprintf "let tot %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string head)
level
(st_term_to_string' level body)
| Tm_Abs { b; q; ascription=c; body } ->
sprintf "(fun (%s%s)\n%s\n ({\n%s%s\n}%s)"
(qual_to_string q)
(binder_to_string b)
(match c.annotated with | None -> "" | Some c -> comp_to_string c)
(indent level)
(st_term_to_string' (indent level) body)
(match c.elaborated with | None -> "" | Some c -> " <: " ^ comp_to_string c)
| Tm_If { b; then_; else_ } ->
sprintf "if (%s)\n%s{\n%s%s\n%s}\n%selse\n%s{\n%s%s\n%s}"
(term_to_string b)
level
(indent level)
(st_term_to_string' (indent level) then_)
level
level
level
(indent level)
(st_term_to_string' (indent level) else_)
level
| Tm_Match {sc; brs} ->
sprintf "match (%s) with %s"
(term_to_string sc)
(branches_to_string brs)
| Tm_IntroPure { p } ->
sprintf "introduce pure (\n%s%s)"
(indent level)
(term_to_string' (indent level) p)
| Tm_ElimExists { p } ->
sprintf "elim_exists %s"
(term_to_string p)
| Tm_IntroExists { p; witnesses } ->
sprintf "introduce\n%s%s\n%swith %s"
(indent level)
(term_to_string' (indent level) p)
level
(term_list_to_string " " witnesses)
| Tm_While { invariant; condition; body } ->
sprintf "while (%s)\n%sinvariant %s\n%s{\n%s%s\n%s}"
(st_term_to_string' level condition)
level
(term_to_string invariant)
level
(indent level)
(st_term_to_string' (indent level) body)
level
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
sprintf "par (<%s> (%s) <%s) (<%s> (%s) <%s)"
(term_to_string pre1)
(st_term_to_string' level body1)
(term_to_string post1)
(term_to_string pre2)
(st_term_to_string' level body2)
(term_to_string post2)
| Tm_Rewrite { t1; t2 } ->
sprintf "rewrite %s %s"
(term_to_string t1)
(term_to_string t2)
| Tm_WithLocal { binder; initializer; body } ->
sprintf "let mut %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
level
(st_term_to_string' level body)
| Tm_WithLocalArray { binder; initializer; length; body } ->
sprintf "let mut %s = [| %s; %s |]\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
(term_to_string length)
level
(st_term_to_string' level body)
| Tm_Admit { ctag; u; typ; post } ->
sprintf "%s<%s> %s%s"
(match ctag with
| STT -> "stt_admit"
| STT_Atomic -> "stt_atomic_admit"
| STT_Ghost -> "stt_ghost_admit")
(universe_to_string 0 u)
(term_to_string typ)
(match post with
| None -> ""
| Some post -> sprintf " %s" (term_to_string post))
| Tm_Unreachable -> "unreachable ()"
| Tm_ProofHintWithBinders { binders; hint_type; t} ->
let with_prefix =
match binders with
| [] -> ""
| _ -> sprintf "with %s." (String.concat " " (T.map binder_to_string binders))
in
let names_to_string = function
| None -> ""
| Some l -> sprintf " [%s]" (String.concat "; " l)
in
let ht, p =
match hint_type with
| ASSERT { p } -> "assert", term_to_string p
| UNFOLD { names; p } -> sprintf "unfold%s" (names_to_string names), term_to_string p
| FOLD { names; p } -> sprintf "fold%s" (names_to_string names), term_to_string p
| RENAME { pairs; goal } ->
sprintf "rewrite each %s"
(String.concat ", "
(T.map
(fun (x, y) -> sprintf "%s as %s" (term_to_string x) (term_to_string y))
pairs)),
(match goal with
| None -> ""
| Some t -> sprintf " in %s" (term_to_string t))
| REWRITE { t1; t2 } ->
sprintf "rewrite %s as %s" (term_to_string t1) (term_to_string t2), ""
| WILD -> "_", ""
| SHOW_PROOF_STATE _ -> "show_proof_state", ""
in
sprintf "%s %s %s; %s" with_prefix ht p
(st_term_to_string' level t)
| Tm_WithInv { name; body; returns_inv } ->
sprintf "with_inv %s %s %s"
(term_to_string name)
(st_term_to_string' level body)
(match returns_inv with
| None -> ""
| Some (b, t) ->
sprintf "\nreturns %s\nensures %s"
(binder_to_string b)
(term_to_string t))
and branches_to_string brs : T.Tac _ =
match brs with
| [] -> ""
| b::bs -> branch_to_string b ^ branches_to_string bs
and branch_to_string br : T.Tac _ =
let (pat, e) = br in
Printf.sprintf "{ %s -> %s }"
(pattern_to_string pat)
(st_term_to_string' "" e)
and pattern_to_string (p:pattern) : T.Tac string =
match p with
| Pat_Cons fv pats ->
Printf.sprintf "(%s %s)"
(String.concat "." fv.fv_name)
(String.concat " " (T.map (fun (p, _) -> pattern_to_string p) pats))
| Pat_Constant c ->
"<constant>"
| Pat_Var x _ ->
T.unseal x
| Pat_Dot_Term None ->
""
| Pat_Dot_Term (Some t) ->
Printf.sprintf "(.??)" | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Printer.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 26,
"end_line": 428,
"start_col": 0,
"start_line": 229
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Syntax.Printer
open FStar.Printf
open Pulse.Syntax.Base
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module Un = FStar.Sealed
module R = FStar.Reflection.V2
let tot_or_ghost_to_string = function
| T.E_Total -> "total"
| T.E_Ghost -> "ghost"
let name_to_string (f:R.name) = String.concat "." f
let dbg_printing : bool = true
// let constant_to_string = function
// | Unit -> "()"
// | Bool true -> "true"
// | Bool false -> "false"
// | Int i -> sprintf "%d" i
let rec universe_to_string (n:nat) (u:universe)
: Tot string (decreases u) =
let open R in
match inspect_universe u with
| Uv_Unk -> "_"
| Uv_Zero -> sprintf "%d" n
| Uv_Succ u -> universe_to_string (n + 1) u
| Uv_BVar x -> if n = 0 then sprintf "%d" x else sprintf "(%d + %d)" x n
| Uv_Max us ->
let r = "(max _)" in
// sprintf "(max %s %s)" (universe_to_string 0 u0) (universe_to_string 0 u1) in
if n = 0 then r else sprintf "%s + %d" r n
| _ -> sprintf "<univ>"
let univ_to_string u = sprintf "u#%s" (universe_to_string 0 u)
let qual_to_string = function
| None -> ""
| Some Implicit -> "#"
let indent (level:string) = level ^ "\t"
let rec collect_binders (until: term' -> bool) (t:term) : list binder & term =
if not (until t.t) then [], t
else (
match t.t with
| Tm_ExistsSL _ b body
| Tm_ForallSL _ b body ->
let bs, t = collect_binders until body in
b::bs, t
| _ -> [], t
)
let rec binder_to_string_paren (b:binder)
: T.Tac string
= sprintf "(%s%s:%s)"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string' "" b.binder_ty)
and term_to_string' (level:string) (t:term)
: T.Tac string
= match t.t with
| Tm_Emp -> "emp"
| Tm_Pure p ->
sprintf "pure (%s)"
(term_to_string' (indent level) p)
| Tm_Star p1 p2 ->
sprintf "%s ** \n%s%s"
(term_to_string' level p1)
level
(term_to_string' level p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
sprintf "(exists* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_ForallSL u b body ->
let bs, body = collect_binders Tm_ForallSL? t in
sprintf "(forall* %s.\n%s%s)"
(T.map binder_to_string_paren bs |> String.concat " ")
level
(term_to_string' (indent level) body)
| Tm_VProp -> "vprop"
| Tm_Inames -> "inames"
| Tm_EmpInames -> "emp_inames"
| Tm_Unknown -> "_"
| Tm_AddInv i is ->
sprintf "add_inv %s %s"
(term_to_string' level i)
(term_to_string' level is)
| Tm_Inv i ->
sprintf "inv %s"
(term_to_string' level i)
| Tm_FStar t ->
T.term_to_string t
let term_to_string t = term_to_string' "" t
let rec binder_to_doc b : T.Tac document =
parens (doc_of_string (T.unseal b.binder_ppname.name)
^^ doc_of_string ":"
^^ term_to_doc b.binder_ty)
and term_to_doc t
: T.Tac document
= match t.t with
| Tm_Emp -> doc_of_string "emp"
| Tm_Pure p -> doc_of_string "pure" ^^ parens (term_to_doc p)
| Tm_Star p1 p2 ->
infix 2 1 (doc_of_string "**")
(term_to_doc p1)
(term_to_doc p2)
| Tm_ExistsSL _ _ _ ->
let bs, body = collect_binders Tm_ExistsSL? t in
parens (doc_of_string "exists*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_ForallSL _ _ _ ->
let bs, body = collect_binders Tm_ForallSL? t in
parens (doc_of_string "forall*" ^/^ (separate (doc_of_string " ") (T.map binder_to_doc bs))
^^ doc_of_string "."
^/^ term_to_doc body)
| Tm_VProp -> doc_of_string "vprop"
| Tm_Inames -> doc_of_string "inames"
| Tm_EmpInames -> doc_of_string "emp_inames"
| Tm_AddInv i is ->
doc_of_string "add_inv" ^/^ parens (term_to_doc i ^^ doc_of_string "," ^^ term_to_doc is)
| Tm_Inv i ->
doc_of_string "inv" ^/^ parens (term_to_doc i)
| Tm_Unknown -> doc_of_string "_"
| Tm_FStar t ->
// Should call term_to_doc when available
doc_of_string (T.term_to_string t)
let binder_to_string (b:binder)
: T.Tac string
= sprintf "%s%s:%s"
(match T.unseal b.binder_attrs with
| [] -> ""
| l -> sprintf "[@@@ %s] " (String.concat ";" (T.map (term_to_string' "") l)))
(T.unseal b.binder_ppname.name)
(term_to_string b.binder_ty)
let ctag_to_string = function
| STT -> "ST"
| STT_Atomic -> "STAtomic"
| STT_Ghost -> "STGhost"
let observability_to_string =
function
| Observable -> "Observable"
| Unobservable -> "Unobservable"
| Neutral -> "Neutral"
let effect_annot_to_string = function
| EffectAnnotSTT -> "stt"
| EffectAnnotGhost -> "stt_ghost"
| EffectAnnotAtomic { opens } -> sprintf "stt_atomic %s" (term_to_string opens)
let comp_to_string (c:comp)
: T.Tac string
= match c with
| C_Tot t ->
sprintf "Tot %s" (term_to_string t)
| C_ST s ->
sprintf "stt %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
| C_STAtomic inames obs s ->
sprintf "stt_atomic %s #%s %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(observability_to_string obs)
(term_to_string inames)
(term_to_string s.pre)
(term_to_string s.post)
| C_STGhost s ->
sprintf "stt_ghost %s (requires\n%s) (ensures\n%s)"
(term_to_string s.res)
(term_to_string s.pre)
(term_to_string s.post)
let term_opt_to_string (t:option term)
: T.Tac string
= match t with
| None -> ""
| Some t -> term_to_string t
let term_list_to_string (sep:string) (t:list term)
: T.Tac string
= String.concat sep (T.map term_to_string t) | {
"checked_file": "/",
"dependencies": [
"Pulse.Syntax.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.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.Syntax.Printer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Sealed",
"short_module": "Un"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Printf",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Pprint",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | level: Prims.string -> t: Pulse.Syntax.Base.st_term -> FStar.Tactics.Effect.Tac Prims.string | FStar.Tactics.Effect.Tac | [] | [
"st_term_to_string'",
"branches_to_string",
"branch_to_string",
"pattern_to_string"
] | [
"Prims.string",
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.__proj__Mkst_term__item__term",
"Pulse.Syntax.Base.term",
"Prims.bool",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.term_to_string",
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Printer.qual_to_string",
"Pulse.Syntax.Printer.dbg_printing",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Printer.binder_to_string",
"Pulse.Syntax.Printer.st_term_to_string'",
"Pulse.Syntax.Base.comp_ascription",
"Pulse.Syntax.Printer.indent",
"Pulse.Syntax.Base.__proj__Mkcomp_ascription__item__annotated",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Printer.comp_to_string",
"Pulse.Syntax.Base.__proj__Mkcomp_ascription__item__elaborated",
"Prims.op_Hat",
"Pulse.Syntax.Base.vprop",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.pattern",
"Pulse.Syntax.Printer.branches_to_string",
"Pulse.Syntax.Printer.term_to_string'",
"Pulse.Syntax.Printer.term_list_to_string",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.ctag",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Printer.universe_to_string",
"Pulse.Syntax.Base.proof_hint_type",
"FStar.Pervasives.Native.Mktuple2",
"FStar.String.concat",
"FStar.Tactics.Util.map",
"Pulse.Syntax.Base.range"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec st_term_to_string' (level: string) (t: st_term) : T.Tac string =
| match t.term with
| Tm_Return { insert_eq = insert_eq ; term = term } ->
sprintf "return_%s %s" (if insert_eq then "" else "_noeq") (term_to_string term)
| Tm_STApp { head = head ; arg_qual = arg_qual ; arg = arg } ->
sprintf "(%s%s %s%s)"
(if dbg_printing then "<stapp>" else "")
(term_to_string head)
(qual_to_string arg_qual)
(term_to_string arg)
| Tm_Bind { binder = binder ; head = head ; body = body } ->
sprintf "let %s = %s;\n%s%s"
(binder_to_string binder)
(st_term_to_string' level head)
level
(st_term_to_string' level body)
| Tm_TotBind { head = head ; binder = binder ; body = body } ->
sprintf "let tot %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string head)
level
(st_term_to_string' level body)
| Tm_Abs { b = b ; q = q ; ascription = c ; body = body } ->
sprintf "(fun (%s%s)\n%s\n ({\n%s%s\n}%s)"
(qual_to_string q)
(binder_to_string b)
(match c.annotated with
| None -> ""
| Some c -> comp_to_string c)
(indent level)
(st_term_to_string' (indent level) body)
(match c.elaborated with
| None -> ""
| Some c -> " <: " ^ comp_to_string c)
| Tm_If { b = b ; then_ = then_ ; else_ = else_ } ->
sprintf "if (%s)\n%s{\n%s%s\n%s}\n%selse\n%s{\n%s%s\n%s}" (term_to_string b) level (indent level)
(st_term_to_string' (indent level) then_) level level level (indent level)
(st_term_to_string' (indent level) else_) level
| Tm_Match { sc = sc ; brs = brs } ->
sprintf "match (%s) with %s" (term_to_string sc) (branches_to_string brs)
| Tm_IntroPure { p = p } ->
sprintf "introduce pure (\n%s%s)" (indent level) (term_to_string' (indent level) p)
| Tm_ElimExists { p = p } -> sprintf "elim_exists %s" (term_to_string p)
| Tm_IntroExists { p = p ; witnesses = witnesses } ->
sprintf "introduce\n%s%s\n%swith %s"
(indent level)
(term_to_string' (indent level) p)
level
(term_list_to_string " " witnesses)
| Tm_While { invariant = invariant ; condition = condition ; body = body } ->
sprintf "while (%s)\n%sinvariant %s\n%s{\n%s%s\n%s}"
(st_term_to_string' level condition)
level
(term_to_string invariant)
level
(indent level)
(st_term_to_string' (indent level) body)
level
| Tm_Par
{ pre1 = pre1 ; body1 = body1 ; post1 = post1 ; pre2 = pre2 ; body2 = body2 ; post2 = post2 } ->
sprintf "par (<%s> (%s) <%s) (<%s> (%s) <%s)"
(term_to_string pre1)
(st_term_to_string' level body1)
(term_to_string post1)
(term_to_string pre2)
(st_term_to_string' level body2)
(term_to_string post2)
| Tm_Rewrite { t1 = t1 ; t2 = t2 } ->
sprintf "rewrite %s %s" (term_to_string t1) (term_to_string t2)
| Tm_WithLocal { binder = binder ; initializer = initializer ; body = body } ->
sprintf "let mut %s = %s;\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
level
(st_term_to_string' level body)
| Tm_WithLocalArray { binder = binder ; initializer = initializer ; length = length ; body = body } ->
sprintf "let mut %s = [| %s; %s |]\n%s%s"
(binder_to_string binder)
(term_to_string initializer)
(term_to_string length)
level
(st_term_to_string' level body)
| Tm_Admit { ctag = ctag ; u = u ; typ = typ ; post = post } ->
sprintf "%s<%s> %s%s"
(match ctag with
| STT -> "stt_admit"
| STT_Atomic -> "stt_atomic_admit"
| STT_Ghost -> "stt_ghost_admit")
(universe_to_string 0 u)
(term_to_string typ)
(match post with
| None -> ""
| Some post -> sprintf " %s" (term_to_string post))
| Tm_Unreachable -> "unreachable ()"
| Tm_ProofHintWithBinders { binders = binders ; hint_type = hint_type ; t = t } ->
let with_prefix =
match binders with
| [] -> ""
| _ -> sprintf "with %s." (String.concat " " (T.map binder_to_string binders))
in
let names_to_string =
function
| None -> ""
| Some l -> sprintf " [%s]" (String.concat "; " l)
in
let ht, p =
match hint_type with
| ASSERT { p = p } -> "assert", term_to_string p
| UNFOLD { names = names ; p = p } ->
sprintf "unfold%s" (names_to_string names), term_to_string p
| FOLD { names = names ; p = p } -> sprintf "fold%s" (names_to_string names), term_to_string p
| RENAME { pairs = pairs ; goal = goal } ->
sprintf "rewrite each %s"
(String.concat ", "
(T.map (fun (x, y) -> sprintf "%s as %s" (term_to_string x) (term_to_string y)) pairs)),
(match goal with
| None -> ""
| Some t -> sprintf " in %s" (term_to_string t))
| REWRITE { t1 = t1 ; t2 = t2 } ->
sprintf "rewrite %s as %s" (term_to_string t1) (term_to_string t2), ""
| WILD -> "_", ""
| SHOW_PROOF_STATE _ -> "show_proof_state", ""
in
sprintf "%s %s %s; %s" with_prefix ht p (st_term_to_string' level t)
| Tm_WithInv { name = name ; body = body ; returns_inv = returns_inv } ->
sprintf "with_inv %s %s %s"
(term_to_string name)
(st_term_to_string' level body)
(match returns_inv with
| None -> ""
| Some (b, t) -> sprintf "\nreturns %s\nensures %s" (binder_to_string b) (term_to_string t)) | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.parse_vlgen_weak_kind | val parse_vlgen_weak_kind (kl: parser_kind) (min: nat) (max: nat{min <= max /\ max < 4294967296})
: Tot parser_kind | val parse_vlgen_weak_kind (kl: parser_kind) (min: nat) (max: nat{min <= max /\ max < 4294967296})
: Tot parser_kind | let parse_vlgen_weak_kind
(kl: parser_kind)
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
: Tot parser_kind
= and_then_kind kl (parse_vlgen_weak_payload_kind min max) | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 58,
"end_line": 488,
"start_col": 0,
"start_line": 483
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len)
inline_for_extraction
let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x
let parse_vlgen_precond
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max
let parse_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t)
= parse_bounded_vlgen min max pk s
`parse_synth`
synth_vlgen min max s
let parse_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
input;
parse_bounded_vlgen_unfold min max pk s input
inline_for_extraction
let synth_bounded_vlgen_payload_recip
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Tot (parse_fldata_strong_t s (U32.v sz))
= x
let serialize_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (serializer (parse_bounded_vlgen_payload min max s sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_serializer (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz) (fun _ -> ())
else
serialize_weaken (parse_bounded_vlgen_payload_kind min max k)
(serialize_synth
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
)
let serialize_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Lemma
(serialize (serialize_bounded_vlgen_payload min max s sz) input == serialize s input)
= serialize_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
input
let serialize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vlgen min max pk s))
= serialize_tagged_union
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s)
let serialize_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: parse_bounded_vldata_strong_t min max s)
: Lemma
(serialize (serialize_bounded_vlgen min max ssk s) input == (
let sp = serialize s input in
serialize ssk (U32.uint_to_t (Seq.length sp)) `Seq.append` sp
))
= serialize_tagged_union_eq
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s)
input;
let tg : bounded_int32 min max = tag_of_bounded_vlgen_payload min max s input in
serialize_bounded_vlgen_payload_unfold min max s tg input
inline_for_extraction
let synth_vlgen_recip
(min: nat)
(max: nat { min <= max } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k } )
(x: t)
: Tot (parse_bounded_vldata_strong_t min max s)
= [@inline_let] let _ =
let sl = Seq.length (serialize s x) in
assert (min <= sl /\ sl <= max)
in
x
let serialize_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (serializer (parse_vlgen min max pk s))
= serialize_synth
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
(serialize_bounded_vlgen min max ssk s)
(synth_vlgen_recip min max s)
()
let serialize_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: t)
: Lemma
(serialize (serialize_vlgen min max ssk s) input == (
let sp = serialize s input in
serialize ssk (U32.uint_to_t (Seq.length sp)) `Seq.append` sp
))
= serialize_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
(serialize_bounded_vlgen min max ssk s)
(synth_vlgen_recip min max s)
()
input;
serialize_bounded_vlgen_unfold min max ssk s input
(* What if we are not sure the serializer exists? *)
inline_for_extraction
noextract
let parse_vlgen_weak_payload_kind
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
: Tot parser_kind
= strong_parser_kind min max None
let parse_vlgen_weak_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(bound: bounded_int32 min max)
: Tot (parser (parse_vlgen_weak_payload_kind min max) t)
= weaken (parse_vlgen_weak_payload_kind min max) (parse_fldata p (U32.v bound))
let parse_vlgen_weak_payload_and_then_cases_injective
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vlgen_weak_payload min max p))
=
and_then_cases_injective_intro
(parse_vlgen_weak_payload min max p)
(fun (x1 x2: bounded_int32 min max) b1 b2 ->
parse_injective
p
(Seq.slice b1 0 (U32.v x1))
(Seq.slice b2 0 (U32.v x2))
)
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
kl: LowParse.Spec.Base.parser_kind ->
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296}
-> LowParse.Spec.Base.parser_kind | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.VLGen.parse_vlgen_weak_payload_kind"
] | [] | false | false | false | false | false | let parse_vlgen_weak_kind (kl: parser_kind) (min: nat) (max: nat{min <= max /\ max < 4294967296})
: Tot parser_kind =
| and_then_kind kl (parse_vlgen_weak_payload_kind min max) | false |
Steel.ST.BitVector.fst | Steel.ST.BitVector.bv_unset | val bv_unset
(#n:US.t)
(#s:G.erased repr)
(bv:bv_t n)
(i:US.t{US.v i < Seq.length s})
: STT unit
(pts_to bv full_perm s)
(fun _ -> pts_to bv full_perm (Seq.upd s (US.v i) false)) | val bv_unset
(#n:US.t)
(#s:G.erased repr)
(bv:bv_t n)
(i:US.t{US.v i < Seq.length s})
: STT unit
(pts_to bv full_perm s)
(fun _ -> pts_to bv full_perm (Seq.upd s (US.v i) false)) | let bv_unset #_ #s bv i = A.write #_ bv #s i false | {
"file_name": "lib/steel/Steel.ST.BitVector.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 50,
"end_line": 43,
"start_col": 0,
"start_line": 43
} | (*
Copyright 2021 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.
Authors: Aseem Rastogi
*)
module Steel.ST.BitVector
open Steel.ST.Effect.Ghost
open Steel.ST.Effect
open Steel.ST.Util
module US = FStar.SizeT
module G = FStar.Ghost
module A = Steel.ST.Array
/// Implementation of bv_t using an array of bool
type bv_t n = a:A.array bool{A.length a == US.v n /\ A.is_full_array a}
let pts_to bv p s = A.pts_to bv p s
let pts_to_length bv s = A.pts_to_length bv s
let alloc n = A.alloc false n
let bv_is_set bv i = A.read bv i
let bv_set #_ #s bv i = A.write #_ bv #s i true | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Effect.Ghost.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.BitVector.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bv: Steel.ST.BitVector.bv_t n ->
i: FStar.SizeT.t{FStar.SizeT.v i < FStar.Seq.Base.length (FStar.Ghost.reveal s)}
-> Steel.ST.Effect.STT Prims.unit | Steel.ST.Effect.STT | [] | [] | [
"FStar.SizeT.t",
"FStar.Ghost.erased",
"Steel.ST.BitVector.repr",
"Steel.ST.BitVector.bv_t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.SizeT.v",
"FStar.Seq.Base.length",
"Prims.bool",
"FStar.Ghost.reveal",
"Steel.ST.Array.write",
"Prims.unit"
] | [] | false | true | false | false | false | let bv_unset #_ #s bv i =
| A.write #_ bv #s i false | false |
Steel.ST.BitVector.fst | Steel.ST.BitVector.alloc | val alloc (n:US.t{US.v n > 0})
: STT (bv_t n) emp (fun r -> pts_to r full_perm (Seq.create (US.v n) false)) | val alloc (n:US.t{US.v n > 0})
: STT (bv_t n) emp (fun r -> pts_to r full_perm (Seq.create (US.v n) false)) | let alloc n = A.alloc false n | {
"file_name": "lib/steel/Steel.ST.BitVector.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 29,
"end_line": 37,
"start_col": 0,
"start_line": 37
} | (*
Copyright 2021 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.
Authors: Aseem Rastogi
*)
module Steel.ST.BitVector
open Steel.ST.Effect.Ghost
open Steel.ST.Effect
open Steel.ST.Util
module US = FStar.SizeT
module G = FStar.Ghost
module A = Steel.ST.Array
/// Implementation of bv_t using an array of bool
type bv_t n = a:A.array bool{A.length a == US.v n /\ A.is_full_array a}
let pts_to bv p s = A.pts_to bv p s
let pts_to_length bv s = A.pts_to_length bv s | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Effect.Ghost.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.BitVector.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: FStar.SizeT.t{FStar.SizeT.v n > 0} -> Steel.ST.Effect.STT (Steel.ST.BitVector.bv_t n) | Steel.ST.Effect.STT | [] | [] | [
"FStar.SizeT.t",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.SizeT.v",
"Steel.ST.Array.alloc",
"Prims.bool",
"Steel.ST.Array.array",
"Steel.ST.BitVector.bv_t"
] | [] | false | true | false | false | false | let alloc n =
| A.alloc false n | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.parse_bounded_vlgen | val parse_bounded_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s)) | val parse_bounded_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s)) | let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s) | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 43,
"end_line": 132,
"start_col": 0,
"start_line": 119
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s: LowParse.Spec.Base.serializer p
-> LowParse.Spec.Base.parser (LowParse.Spec.VLGen.parse_bounded_vlgen_kind sk min max k)
(LowParse.Spec.VLData.parse_bounded_vldata_strong_t min max s) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.Combinators.parse_tagged_union",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.tag_of_bounded_vlgen_payload",
"LowParse.Spec.VLGen.parse_bounded_vlgen_payload_kind",
"LowParse.Spec.VLGen.parse_bounded_vlgen_payload",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind"
] | [] | false | false | false | false | false | let parse_bounded_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s)) =
| parse_tagged_union pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s) | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.parse_vlgen_precond | val parse_vlgen_precond (min: nat) (max: nat{min <= max}) (k: parser_kind) : GTot bool | val parse_vlgen_precond (min: nat) (max: nat{min <= max}) (k: parser_kind) : GTot bool | let parse_vlgen_precond
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 56,
"end_line": 232,
"start_col": 0,
"start_line": 225
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len)
inline_for_extraction
let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | min: Prims.nat -> max: Prims.nat{min <= max} -> k: LowParse.Spec.Base.parser_kind
-> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"Prims.op_AmpAmp",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.bool"
] | [] | false | false | false | false | false | let parse_vlgen_precond (min: nat) (max: nat{min <= max}) (k: parser_kind) : GTot bool =
| match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.synth_bounded_vlgen_payload | val synth_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz) | val synth_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz) | let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 33,
"start_col": 0,
"start_line": 23
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
sz: LowParse.Spec.BoundedInt.bounded_int32 min max ->
x: LowParse.Spec.FLData.parse_fldata_strong_t s (FStar.UInt32.v sz)
-> LowParse.Spec.Base.refine_with_tag (LowParse.Spec.VLGen.tag_of_bounded_vlgen_payload min max s)
sz | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"FStar.UInt32.v",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.tag_of_bounded_vlgen_payload"
] | [] | false | false | false | false | false | let synth_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz) =
| x | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.tag_of_bounded_vlgen_payload | val tag_of_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max) | val tag_of_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max) | let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x)) | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 20,
"start_col": 0,
"start_line": 11
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
x: LowParse.Spec.VLData.parse_bounded_vldata_strong_t min max s
-> Prims.GTot (LowParse.Spec.BoundedInt.bounded_int32 min max) | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"FStar.UInt32.uint_to_t",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.BoundedInt.bounded_int32"
] | [] | false | false | false | false | false | let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max) =
| U32.uint_to_t (Seq.length (serialize s x)) | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.parse_bounded_vlgen_payload | val parse_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot
(parser (parse_bounded_vlgen_payload_kind min max k)
(refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)) | val parse_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot
(parser (parse_bounded_vlgen_payload_kind min max k)
(refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)) | let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz) | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 47,
"end_line": 80,
"start_col": 0,
"start_line": 58
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
sz: LowParse.Spec.BoundedInt.bounded_int32 min max
-> LowParse.Spec.Base.parser (LowParse.Spec.VLGen.parse_bounded_vlgen_payload_kind min max k)
(LowParse.Spec.Base.refine_with_tag (LowParse.Spec.VLGen.tag_of_bounded_vlgen_payload min
max
s)
sz) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Combinators.fail_parser",
"LowParse.Spec.VLGen.parse_bounded_vlgen_payload_kind",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.tag_of_bounded_vlgen_payload",
"Prims.bool",
"LowParse.Spec.Base.weaken",
"LowParse.Spec.FLData.parse_fldata_kind",
"FStar.UInt32.v",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Spec.VLGen.synth_bounded_vlgen_payload",
"Prims.op_BarBar",
"Prims.op_GreaterThan",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high"
] | [] | false | false | false | false | false | let parse_bounded_vlgen_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot
(parser (parse_bounded_vlgen_payload_kind min max k)
(refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)) =
| let bounds_off =
k.parser_kind_low > U32.v sz ||
(match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz)
in
if bounds_off
then
fail_parser (parse_bounded_vlgen_payload_kind min max k)
(refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
((parse_fldata_strong s (U32.v sz)) `parse_synth` (synth_bounded_vlgen_payload min max s sz)) | false |
Steel.ST.BitVector.fst | Steel.ST.BitVector.bv_set | val bv_set
(#n:US.t)
(#s:G.erased repr)
(bv:bv_t n)
(i:US.t{US.v i < Seq.length s})
: STT unit
(pts_to bv full_perm s)
(fun _ -> pts_to bv full_perm (Seq.upd s (US.v i) true)) | val bv_set
(#n:US.t)
(#s:G.erased repr)
(bv:bv_t n)
(i:US.t{US.v i < Seq.length s})
: STT unit
(pts_to bv full_perm s)
(fun _ -> pts_to bv full_perm (Seq.upd s (US.v i) true)) | let bv_set #_ #s bv i = A.write #_ bv #s i true | {
"file_name": "lib/steel/Steel.ST.BitVector.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 47,
"end_line": 41,
"start_col": 0,
"start_line": 41
} | (*
Copyright 2021 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.
Authors: Aseem Rastogi
*)
module Steel.ST.BitVector
open Steel.ST.Effect.Ghost
open Steel.ST.Effect
open Steel.ST.Util
module US = FStar.SizeT
module G = FStar.Ghost
module A = Steel.ST.Array
/// Implementation of bv_t using an array of bool
type bv_t n = a:A.array bool{A.length a == US.v n /\ A.is_full_array a}
let pts_to bv p s = A.pts_to bv p s
let pts_to_length bv s = A.pts_to_length bv s
let alloc n = A.alloc false n
let bv_is_set bv i = A.read bv i | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Effect.Ghost.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.BitVector.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bv: Steel.ST.BitVector.bv_t n ->
i: FStar.SizeT.t{FStar.SizeT.v i < FStar.Seq.Base.length (FStar.Ghost.reveal s)}
-> Steel.ST.Effect.STT Prims.unit | Steel.ST.Effect.STT | [] | [] | [
"FStar.SizeT.t",
"FStar.Ghost.erased",
"Steel.ST.BitVector.repr",
"Steel.ST.BitVector.bv_t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.SizeT.v",
"FStar.Seq.Base.length",
"Prims.bool",
"FStar.Ghost.reveal",
"Steel.ST.Array.write",
"Prims.unit"
] | [] | false | true | false | false | false | let bv_set #_ #s bv i =
| A.write #_ bv #s i true | false |
Vale.Def.Words.Two_s.fsti | Vale.Def.Words.Two_s.two_map | val two_map (#a #b: Type) (f: (a -> b)) (x: two a) : two b | val two_map (#a #b: Type) (f: (a -> b)) (x: two a) : two b | let two_map (#a #b:Type) (f:a -> b) (x:two a) : two b =
let Mktwo x0 x1 = x in
Mktwo (f x0) (f x1) | {
"file_name": "vale/specs/defs/Vale.Def.Words.Two_s.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 7,
"start_col": 7,
"start_line": 5
} | module Vale.Def.Words.Two_s
open Vale.Def.Words_s
open FStar.Mul | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Def.Words.Two_s.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> b) -> x: Vale.Def.Words_s.two a -> Vale.Def.Words_s.two b | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.Mktwo"
] | [] | false | false | false | true | false | let two_map (#a #b: Type) (f: (a -> b)) (x: two a) : two b =
| let Mktwo x0 x1 = x in
Mktwo (f x0) (f x1) | false |
Vale.Def.Words.Two_s.fsti | Vale.Def.Words.Two_s.two_map2 | val two_map2 (#a #b: Type) (f: (a -> a -> b)) (x y: two a) : two b | val two_map2 (#a #b: Type) (f: (a -> a -> b)) (x y: two a) : two b | let two_map2 (#a #b:Type) (f:a -> a -> b) (x y:two a) : two b =
let Mktwo x0 x1 = x in
let Mktwo y0 y1 = y in
Mktwo (f x0 y0) (f x1 y1) | {
"file_name": "vale/specs/defs/Vale.Def.Words.Two_s.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 12,
"start_col": 7,
"start_line": 9
} | module Vale.Def.Words.Two_s
open Vale.Def.Words_s
open FStar.Mul
unfold let two_map (#a #b:Type) (f:a -> b) (x:two a) : two b =
let Mktwo x0 x1 = x in
Mktwo (f x0) (f x1) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Def.Words.Two_s.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> _: a -> b) -> x: Vale.Def.Words_s.two a -> y: Vale.Def.Words_s.two a
-> Vale.Def.Words_s.two b | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.Mktwo"
] | [] | false | false | false | true | false | let two_map2 (#a #b: Type) (f: (a -> a -> b)) (x y: two a) : two b =
| let Mktwo x0 x1 = x in
let Mktwo y0 y1 = y in
Mktwo (f x0 y0) (f x1 y1) | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.parse_vlgen | val parse_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t) | val parse_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t) | let parse_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t)
= parse_bounded_vlgen min max pk s
`parse_synth`
synth_vlgen min max s | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 23,
"end_line": 246,
"start_col": 0,
"start_line": 234
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len)
inline_for_extraction
let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x
let parse_vlgen_precond
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond min max k}
-> LowParse.Spec.Base.parser (LowParse.Spec.VLGen.parse_bounded_vlgen_kind sk min max k) t | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Spec.VLGen.synth_vlgen"
] | [] | false | false | false | false | false | let parse_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t) =
| (parse_bounded_vlgen min max pk s) `parse_synth` (synth_vlgen min max s) | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.parse_bounded_vlgen_payload_kind | val parse_bounded_vlgen_payload_kind (min: nat) (max: nat{min <= max}) (k: parser_kind)
: Tot parser_kind | val parse_bounded_vlgen_payload_kind (min: nat) (max: nat{min <= max}) (k: parser_kind)
: Tot parser_kind | let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
) | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 56,
"start_col": 0,
"start_line": 36
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | min: Prims.nat -> max: Prims.nat{min <= max} -> k: LowParse.Spec.Base.parser_kind
-> LowParse.Spec.Base.parser_kind | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.strong_parser_kind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.parser_kind_metadata_some",
"LowParse.Spec.Base.ParserKindMetadataFail",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.None",
"LowParse.Spec.Base.parser_kind_metadata_t",
"Prims.op_LessThan",
"Prims.bool",
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"Prims.l_and",
"Prims.op_GreaterThan",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low"
] | [] | false | false | false | false | false | let parse_bounded_vlgen_payload_kind (min: nat) (max: nat{min <= max}) (k: parser_kind)
: Tot parser_kind =
| [@@ inline_let ]let kmin = k.parser_kind_low in
[@@ inline_let ]let min' = if kmin > min then kmin else min in
[@@ inline_let ]let max' =
match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@@ inline_let ]let max' = if max' < min' then min' else max' in
strong_parser_kind min'
max'
(match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None) | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.serialize_bounded_vlgen | val serialize_bounded_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk {sk.parser_kind_subkind == Some ParserStrong})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vlgen min max pk s)) | val serialize_bounded_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk {sk.parser_kind_subkind == Some ParserStrong})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vlgen min max pk s)) | let serialize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vlgen min max pk s))
= serialize_tagged_union
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s) | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 47,
"end_line": 358,
"start_col": 0,
"start_line": 344
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len)
inline_for_extraction
let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x
let parse_vlgen_precond
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max
let parse_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t)
= parse_bounded_vlgen min max pk s
`parse_synth`
synth_vlgen min max s
let parse_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
input;
parse_bounded_vlgen_unfold min max pk s input
inline_for_extraction
let synth_bounded_vlgen_payload_recip
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Tot (parse_fldata_strong_t s (U32.v sz))
= x
let serialize_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (serializer (parse_bounded_vlgen_payload min max s sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_serializer (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz) (fun _ -> ())
else
serialize_weaken (parse_bounded_vlgen_payload_kind min max k)
(serialize_synth
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
)
let serialize_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Lemma
(serialize (serialize_bounded_vlgen_payload min max s sz) input == serialize s input)
= serialize_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
input | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296} ->
ssk:
LowParse.Spec.Base.serializer pk
{ Mkparser_kind'?.parser_kind_subkind sk ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->
s: LowParse.Spec.Base.serializer p
-> LowParse.Spec.Base.serializer (LowParse.Spec.VLGen.parse_bounded_vlgen min max pk s) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.Combinators.serialize_tagged_union",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.tag_of_bounded_vlgen_payload",
"LowParse.Spec.VLGen.parse_bounded_vlgen_payload_kind",
"LowParse.Spec.VLGen.parse_bounded_vlgen_payload",
"LowParse.Spec.VLGen.serialize_bounded_vlgen_payload",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLGen.parse_bounded_vlgen"
] | [] | false | false | false | false | false | let serialize_bounded_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk {sk.parser_kind_subkind == Some ParserStrong})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vlgen min max pk s)) =
| serialize_tagged_union ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s) | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.synth_vlgen_recip | val synth_vlgen_recip
(min: nat)
(max: nat{min <= max})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(x: t)
: Tot (parse_bounded_vldata_strong_t min max s) | val synth_vlgen_recip
(min: nat)
(max: nat{min <= max})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(x: t)
: Tot (parse_bounded_vldata_strong_t min max s) | let synth_vlgen_recip
(min: nat)
(max: nat { min <= max } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k } )
(x: t)
: Tot (parse_bounded_vldata_strong_t min max s)
= [@inline_let] let _ =
let sl = Seq.length (serialize s x) in
assert (min <= sl /\ sl <= max)
in
x | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 398,
"start_col": 0,
"start_line": 385
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len)
inline_for_extraction
let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x
let parse_vlgen_precond
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max
let parse_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t)
= parse_bounded_vlgen min max pk s
`parse_synth`
synth_vlgen min max s
let parse_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
input;
parse_bounded_vlgen_unfold min max pk s input
inline_for_extraction
let synth_bounded_vlgen_payload_recip
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Tot (parse_fldata_strong_t s (U32.v sz))
= x
let serialize_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (serializer (parse_bounded_vlgen_payload min max s sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_serializer (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz) (fun _ -> ())
else
serialize_weaken (parse_bounded_vlgen_payload_kind min max k)
(serialize_synth
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
)
let serialize_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Lemma
(serialize (serialize_bounded_vlgen_payload min max s sz) input == serialize s input)
= serialize_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
input
let serialize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vlgen min max pk s))
= serialize_tagged_union
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s)
let serialize_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: parse_bounded_vldata_strong_t min max s)
: Lemma
(serialize (serialize_bounded_vlgen min max ssk s) input == (
let sp = serialize s input in
serialize ssk (U32.uint_to_t (Seq.length sp)) `Seq.append` sp
))
= serialize_tagged_union_eq
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s)
input;
let tg : bounded_int32 min max = tag_of_bounded_vlgen_payload min max s input in
serialize_bounded_vlgen_payload_unfold min max s tg input | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max} ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond min max k} ->
x: t
-> LowParse.Spec.VLData.parse_bounded_vldata_strong_t min max s | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"Prims.unit",
"Prims._assert",
"Prims.l_and",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t"
] | [] | false | false | false | false | false | let synth_vlgen_recip
(min: nat)
(max: nat{min <= max})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(x: t)
: Tot (parse_bounded_vldata_strong_t min max s) =
| [@@ inline_let ]let _ =
let sl = Seq.length (serialize s x) in
assert (min <= sl /\ sl <= max)
in
x | false |
Pulse.Lib.Forall.Util.fst | Pulse.Lib.Forall.Util.elim | val elim : x: a -> Pulse.Lib.Core.stt_ghost Prims.unit (forall* (x: a). p x) (fun _ -> p x) | let elim #a #p = Pulse.Lib.Forall.elim_forall #a #p | {
"file_name": "share/steel/examples/pulse/lib/Pulse.Lib.Forall.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 51,
"end_line": 24,
"start_col": 0,
"start_line": 24
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Lib.Forall.Util
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick.Util
include Pulse.Lib.Forall
module I = Pulse.Lib.Stick.Util | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.Util.fst.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Forall.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.Forall.Util.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Lib.Stick.Util",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Forall",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Forall",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Forall",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> Pulse.Lib.Core.stt_ghost Prims.unit (forall* (x: a). p x) (fun _ -> p x) | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.Core.vprop",
"Pulse.Lib.Forall.elim_forall",
"Pulse.Lib.Core.stt_ghost",
"Prims.unit",
"Pulse.Lib.Forall.op_forall_Star"
] | [] | false | false | false | false | false | let elim #a #p =
| Pulse.Lib.Forall.elim_forall #a #p | false |
|
Pulse.Lib.Forall.Util.fst | Pulse.Lib.Forall.Util.intro | val intro : v: Pulse.Lib.Core.vprop -> f_elim: (x: a -> Pulse.Lib.Core.stt_ghost Prims.unit v (fun _ -> p x))
-> Pulse.Lib.Core.stt_ghost Prims.unit v (fun _ -> forall* (x: a). p x) | let intro #a #p = Pulse.Lib.Forall.intro_forall #a #p | {
"file_name": "share/steel/examples/pulse/lib/Pulse.Lib.Forall.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 53,
"end_line": 23,
"start_col": 0,
"start_line": 23
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Lib.Forall.Util
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick.Util
include Pulse.Lib.Forall
module I = Pulse.Lib.Stick.Util | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.Util.fst.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Forall.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.Forall.Util.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Lib.Stick.Util",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Forall",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Forall",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Forall",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: Pulse.Lib.Core.vprop -> f_elim: (x: a -> Pulse.Lib.Core.stt_ghost Prims.unit v (fun _ -> p x))
-> Pulse.Lib.Core.stt_ghost Prims.unit v (fun _ -> forall* (x: a). p x) | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.Core.vprop",
"Pulse.Lib.Forall.intro_forall",
"Pulse.Lib.Core.stt_ghost",
"Prims.unit",
"Pulse.Lib.Forall.op_forall_Star"
] | [] | false | false | false | false | false | let intro #a #p =
| Pulse.Lib.Forall.intro_forall #a #p | false |
|
Vale.Def.Words.Two_s.fsti | Vale.Def.Words.Two_s.two_reverse | val two_reverse (#a: Type) (x: two a) : two a | val two_reverse (#a: Type) (x: two a) : two a | let two_reverse (#a:Type) (x:two a) : two a =
let Mktwo x0 x1 = x in
Mktwo x1 x0 | {
"file_name": "vale/specs/defs/Vale.Def.Words.Two_s.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 45,
"start_col": 0,
"start_line": 43
} | module Vale.Def.Words.Two_s
open Vale.Def.Words_s
open FStar.Mul
unfold let two_map (#a #b:Type) (f:a -> b) (x:two a) : two b =
let Mktwo x0 x1 = x in
Mktwo (f x0) (f x1)
unfold let two_map2 (#a #b:Type) (f:a -> a -> b) (x y:two a) : two b =
let Mktwo x0 x1 = x in
let Mktwo y0 y1 = y in
Mktwo (f x0 y0) (f x1 y1)
unfold
let nat_to_two_unfold (size:nat) (n:natN (pow2 (2 * size))) : two (natN (pow2 size)) =
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
Mktwo (n % n1) ((n / n1) % n1)
let nat_to_two (size:nat) (n:natN (pow2 (2 * size))) : two (natN (pow2 size)) =
nat_to_two_unfold size n
unfold
let two_to_nat_unfold (size:nat) (x:two (natN (pow2 size))) : natN (pow2 (2 * size)) =
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let Mktwo x0 x1 = x in
int_to_natN n2 (x0 + x1 * n1)
let two_to_nat (size:nat) (x:two (natN (pow2 size))) : natN (pow2 (2 * size)) =
two_to_nat_unfold size x
let two_select (#a:Type) (x:two a) (selector:nat1) : a =
match selector with
| 0 -> x.lo
| 1 -> x.hi
let two_insert (#a:Type) (x:two a) (y:a) (selector:nat1) : two a =
match selector with
| 0 -> Mktwo y x.hi
| 1 -> Mktwo x.lo y | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Def.Words.Two_s.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Words_s.two a -> Vale.Def.Words_s.two a | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.Mktwo"
] | [] | false | false | false | true | false | let two_reverse (#a: Type) (x: two a) : two a =
| let Mktwo x0 x1 = x in
Mktwo x1 x0 | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.parse_vlgen_weak_payload_kind | val parse_vlgen_weak_payload_kind (min: nat) (max: nat{min <= max /\ max < 4294967296})
: Tot parser_kind | val parse_vlgen_weak_payload_kind (min: nat) (max: nat{min <= max /\ max < 4294967296})
: Tot parser_kind | let parse_vlgen_weak_payload_kind
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
: Tot parser_kind
= strong_parser_kind min max None | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 33,
"end_line": 451,
"start_col": 0,
"start_line": 447
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len)
inline_for_extraction
let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x
let parse_vlgen_precond
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max
let parse_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t)
= parse_bounded_vlgen min max pk s
`parse_synth`
synth_vlgen min max s
let parse_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
input;
parse_bounded_vlgen_unfold min max pk s input
inline_for_extraction
let synth_bounded_vlgen_payload_recip
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Tot (parse_fldata_strong_t s (U32.v sz))
= x
let serialize_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (serializer (parse_bounded_vlgen_payload min max s sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_serializer (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz) (fun _ -> ())
else
serialize_weaken (parse_bounded_vlgen_payload_kind min max k)
(serialize_synth
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
)
let serialize_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Lemma
(serialize (serialize_bounded_vlgen_payload min max s sz) input == serialize s input)
= serialize_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
input
let serialize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vlgen min max pk s))
= serialize_tagged_union
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s)
let serialize_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: parse_bounded_vldata_strong_t min max s)
: Lemma
(serialize (serialize_bounded_vlgen min max ssk s) input == (
let sp = serialize s input in
serialize ssk (U32.uint_to_t (Seq.length sp)) `Seq.append` sp
))
= serialize_tagged_union_eq
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s)
input;
let tg : bounded_int32 min max = tag_of_bounded_vlgen_payload min max s input in
serialize_bounded_vlgen_payload_unfold min max s tg input
inline_for_extraction
let synth_vlgen_recip
(min: nat)
(max: nat { min <= max } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k } )
(x: t)
: Tot (parse_bounded_vldata_strong_t min max s)
= [@inline_let] let _ =
let sl = Seq.length (serialize s x) in
assert (min <= sl /\ sl <= max)
in
x
let serialize_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (serializer (parse_vlgen min max pk s))
= serialize_synth
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
(serialize_bounded_vlgen min max ssk s)
(synth_vlgen_recip min max s)
()
let serialize_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: t)
: Lemma
(serialize (serialize_vlgen min max ssk s) input == (
let sp = serialize s input in
serialize ssk (U32.uint_to_t (Seq.length sp)) `Seq.append` sp
))
= serialize_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
(serialize_bounded_vlgen min max ssk s)
(synth_vlgen_recip min max s)
()
input;
serialize_bounded_vlgen_unfold min max ssk s input
(* What if we are not sure the serializer exists? *)
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | min: Prims.nat -> max: Prims.nat{min <= max /\ max < 4294967296} -> LowParse.Spec.Base.parser_kind | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.strong_parser_kind",
"FStar.Pervasives.Native.None",
"LowParse.Spec.Base.parser_kind_metadata_some",
"LowParse.Spec.Base.parser_kind"
] | [] | false | false | false | false | false | let parse_vlgen_weak_payload_kind (min: nat) (max: nat{min <= max /\ max < 4294967296})
: Tot parser_kind =
| strong_parser_kind min max None | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.parse_vlgen_weak_payload | val parse_vlgen_weak_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(bound: bounded_int32 min max)
: Tot (parser (parse_vlgen_weak_payload_kind min max) t) | val parse_vlgen_weak_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(bound: bounded_int32 min max)
: Tot (parser (parse_vlgen_weak_payload_kind min max) t) | let parse_vlgen_weak_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(bound: bounded_int32 min max)
: Tot (parser (parse_vlgen_weak_payload_kind min max) t)
= weaken (parse_vlgen_weak_payload_kind min max) (parse_fldata p (U32.v bound)) | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 79,
"end_line": 461,
"start_col": 0,
"start_line": 453
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len)
inline_for_extraction
let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x
let parse_vlgen_precond
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max
let parse_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t)
= parse_bounded_vlgen min max pk s
`parse_synth`
synth_vlgen min max s
let parse_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
input;
parse_bounded_vlgen_unfold min max pk s input
inline_for_extraction
let synth_bounded_vlgen_payload_recip
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Tot (parse_fldata_strong_t s (U32.v sz))
= x
let serialize_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (serializer (parse_bounded_vlgen_payload min max s sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_serializer (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz) (fun _ -> ())
else
serialize_weaken (parse_bounded_vlgen_payload_kind min max k)
(serialize_synth
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
)
let serialize_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Lemma
(serialize (serialize_bounded_vlgen_payload min max s sz) input == serialize s input)
= serialize_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
input
let serialize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vlgen min max pk s))
= serialize_tagged_union
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s)
let serialize_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: parse_bounded_vldata_strong_t min max s)
: Lemma
(serialize (serialize_bounded_vlgen min max ssk s) input == (
let sp = serialize s input in
serialize ssk (U32.uint_to_t (Seq.length sp)) `Seq.append` sp
))
= serialize_tagged_union_eq
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s)
input;
let tg : bounded_int32 min max = tag_of_bounded_vlgen_payload min max s input in
serialize_bounded_vlgen_payload_unfold min max s tg input
inline_for_extraction
let synth_vlgen_recip
(min: nat)
(max: nat { min <= max } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k } )
(x: t)
: Tot (parse_bounded_vldata_strong_t min max s)
= [@inline_let] let _ =
let sl = Seq.length (serialize s x) in
assert (min <= sl /\ sl <= max)
in
x
let serialize_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (serializer (parse_vlgen min max pk s))
= serialize_synth
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
(serialize_bounded_vlgen min max ssk s)
(synth_vlgen_recip min max s)
()
let serialize_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: t)
: Lemma
(serialize (serialize_vlgen min max ssk s) input == (
let sp = serialize s input in
serialize ssk (U32.uint_to_t (Seq.length sp)) `Seq.append` sp
))
= serialize_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
(serialize_bounded_vlgen min max ssk s)
(synth_vlgen_recip min max s)
()
input;
serialize_bounded_vlgen_unfold min max ssk s input
(* What if we are not sure the serializer exists? *)
inline_for_extraction
noextract
let parse_vlgen_weak_payload_kind
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
: Tot parser_kind
= strong_parser_kind min max None | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296} ->
p: LowParse.Spec.Base.parser k t ->
bound: LowParse.Spec.BoundedInt.bounded_int32 min max
-> LowParse.Spec.Base.parser (LowParse.Spec.VLGen.parse_vlgen_weak_payload_kind min max) t | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.weaken",
"LowParse.Spec.VLGen.parse_vlgen_weak_payload_kind",
"LowParse.Spec.FLData.parse_fldata_kind",
"FStar.UInt32.v",
"LowParse.Spec.FLData.parse_fldata"
] | [] | false | false | false | false | false | let parse_vlgen_weak_payload
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(bound: bounded_int32 min max)
: Tot (parser (parse_vlgen_weak_payload_kind min max) t) =
| weaken (parse_vlgen_weak_payload_kind min max) (parse_fldata p (U32.v bound)) | false |
Vale.Def.Words.Two_s.fsti | Vale.Def.Words.Two_s.two_select | val two_select (#a: Type) (x: two a) (selector: nat1) : a | val two_select (#a: Type) (x: two a) (selector: nat1) : a | let two_select (#a:Type) (x:two a) (selector:nat1) : a =
match selector with
| 0 -> x.lo
| 1 -> x.hi | {
"file_name": "vale/specs/defs/Vale.Def.Words.Two_s.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 36,
"start_col": 0,
"start_line": 33
} | module Vale.Def.Words.Two_s
open Vale.Def.Words_s
open FStar.Mul
unfold let two_map (#a #b:Type) (f:a -> b) (x:two a) : two b =
let Mktwo x0 x1 = x in
Mktwo (f x0) (f x1)
unfold let two_map2 (#a #b:Type) (f:a -> a -> b) (x y:two a) : two b =
let Mktwo x0 x1 = x in
let Mktwo y0 y1 = y in
Mktwo (f x0 y0) (f x1 y1)
unfold
let nat_to_two_unfold (size:nat) (n:natN (pow2 (2 * size))) : two (natN (pow2 size)) =
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
Mktwo (n % n1) ((n / n1) % n1)
let nat_to_two (size:nat) (n:natN (pow2 (2 * size))) : two (natN (pow2 size)) =
nat_to_two_unfold size n
unfold
let two_to_nat_unfold (size:nat) (x:two (natN (pow2 size))) : natN (pow2 (2 * size)) =
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let Mktwo x0 x1 = x in
int_to_natN n2 (x0 + x1 * n1)
let two_to_nat (size:nat) (x:two (natN (pow2 size))) : natN (pow2 (2 * size)) =
two_to_nat_unfold size x | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Def.Words.Two_s.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Words_s.two a -> selector: Vale.Def.Words_s.nat1 -> a | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.nat1",
"Vale.Def.Words_s.__proj__Mktwo__item__lo",
"Vale.Def.Words_s.__proj__Mktwo__item__hi"
] | [] | false | false | false | true | false | let two_select (#a: Type) (x: two a) (selector: nat1) : a =
| match selector with
| 0 -> x.lo
| 1 -> x.hi | false |
Vale.Def.Words.Two_s.fsti | Vale.Def.Words.Two_s.nat_to_two | val nat_to_two (size: nat) (n: natN (pow2 (2 * size))) : two (natN (pow2 size)) | val nat_to_two (size: nat) (n: natN (pow2 (2 * size))) : two (natN (pow2 size)) | let nat_to_two (size:nat) (n:natN (pow2 (2 * size))) : two (natN (pow2 size)) =
nat_to_two_unfold size n | {
"file_name": "vale/specs/defs/Vale.Def.Words.Two_s.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 21,
"start_col": 0,
"start_line": 20
} | module Vale.Def.Words.Two_s
open Vale.Def.Words_s
open FStar.Mul
unfold let two_map (#a #b:Type) (f:a -> b) (x:two a) : two b =
let Mktwo x0 x1 = x in
Mktwo (f x0) (f x1)
unfold let two_map2 (#a #b:Type) (f:a -> a -> b) (x y:two a) : two b =
let Mktwo x0 x1 = x in
let Mktwo y0 y1 = y in
Mktwo (f x0 y0) (f x1 y1)
unfold
let nat_to_two_unfold (size:nat) (n:natN (pow2 (2 * size))) : two (natN (pow2 size)) =
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
Mktwo (n % n1) ((n / n1) % n1) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Def.Words.Two_s.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | size: Prims.nat -> n: Vale.Def.Words_s.natN (Prims.pow2 (2 * size))
-> Vale.Def.Words_s.two (Vale.Def.Words_s.natN (Prims.pow2 size)) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words.Two_s.nat_to_two_unfold",
"Vale.Def.Words_s.two"
] | [] | false | false | false | false | false | let nat_to_two (size: nat) (n: natN (pow2 (2 * size))) : two (natN (pow2 size)) =
| nat_to_two_unfold size n | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.parse_vlgen_unfold | val parse_vlgen_unfold
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Seq.length (serialize s x) = U32.v len /\ res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None) | val parse_vlgen_unfold
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Seq.length (serialize s x) = U32.v len /\ res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None) | let parse_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
input;
parse_bounded_vlgen_unfold min max pk s input | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 47,
"end_line": 282,
"start_col": 0,
"start_line": 248
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len)
inline_for_extraction
let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x
let parse_vlgen_precond
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max
let parse_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t)
= parse_bounded_vlgen min max pk s
`parse_synth`
synth_vlgen min max s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296} ->
pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 min max) ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond min max k} ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
(let res = LowParse.Spec.Base.parse (LowParse.Spec.VLGen.parse_vlgen min max pk s) input in
(match LowParse.Spec.Base.parse pk input with
| FStar.Pervasives.Native.None #_ -> res == FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ len sz) ->
(match FStar.Seq.Base.length input < sz + FStar.UInt32.v len with
| true -> res == FStar.Pervasives.Native.None
| _ ->
let input' = FStar.Seq.Base.slice input sz (sz + FStar.UInt32.v len) in
(match LowParse.Spec.Base.parse p input' with
| FStar.Pervasives.Native.Some
#_
(FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) ->
(match consumed_x = FStar.UInt32.v len with
| true ->
FStar.Seq.Base.length (LowParse.Spec.Base.serialize s x) =
FStar.UInt32.v len /\
res == FStar.Pervasives.Native.Some (x, sz + FStar.UInt32.v len)
| _ -> res == FStar.Pervasives.Native.None)
<:
Type0
| _ -> res == FStar.Pervasives.Native.None)
<:
Type0)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Bytes.bytes",
"LowParse.Spec.VLGen.parse_bounded_vlgen_unfold",
"Prims.unit",
"LowParse.Spec.Combinators.parse_synth_eq",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Spec.VLGen.synth_vlgen",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Base.parse",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"FStar.Pervasives.Native.None",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.op_Addition",
"FStar.UInt32.v",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"LowParse.Spec.Base.serialize",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"LowParse.Spec.VLGen.parse_vlgen",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let parse_vlgen_unfold
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Seq.length (serialize s x) = U32.v len /\ res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None) =
| parse_synth_eq (parse_bounded_vlgen min max pk s) (synth_vlgen min max s) input;
parse_bounded_vlgen_unfold min max pk s input | false |
Vale.Def.Words.Two_s.fsti | Vale.Def.Words.Two_s.nat_to_two_unfold | val nat_to_two_unfold (size: nat) (n: natN (pow2 (2 * size))) : two (natN (pow2 size)) | val nat_to_two_unfold (size: nat) (n: natN (pow2 (2 * size))) : two (natN (pow2 size)) | let nat_to_two_unfold (size:nat) (n:natN (pow2 (2 * size))) : two (natN (pow2 size)) =
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
Mktwo (n % n1) ((n / n1) % n1) | {
"file_name": "vale/specs/defs/Vale.Def.Words.Two_s.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 18,
"start_col": 0,
"start_line": 15
} | module Vale.Def.Words.Two_s
open Vale.Def.Words_s
open FStar.Mul
unfold let two_map (#a #b:Type) (f:a -> b) (x:two a) : two b =
let Mktwo x0 x1 = x in
Mktwo (f x0) (f x1)
unfold let two_map2 (#a #b:Type) (f:a -> a -> b) (x y:two a) : two b =
let Mktwo x0 x1 = x in
let Mktwo y0 y1 = y in
Mktwo (f x0 y0) (f x1 y1) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Def.Words.Two_s.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | size: Prims.nat -> n: Vale.Def.Words_s.natN (Prims.pow2 (2 * size))
-> Vale.Def.Words_s.two (Vale.Def.Words_s.natN (Prims.pow2 size)) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.Mktwo",
"Prims.op_Modulus",
"Prims.op_Division",
"Prims.pos",
"Vale.Def.Words_s.pow2_norm",
"Vale.Def.Words_s.two"
] | [] | false | false | false | false | false | let nat_to_two_unfold (size: nat) (n: natN (pow2 (2 * size))) : two (natN (pow2 size)) =
| let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
Mktwo (n % n1) ((n / n1) % n1) | false |
Vale.Def.Words.Two_s.fsti | Vale.Def.Words.Two_s.two_to_nat_unfold | val two_to_nat_unfold (size: nat) (x: two (natN (pow2 size))) : natN (pow2 (2 * size)) | val two_to_nat_unfold (size: nat) (x: two (natN (pow2 size))) : natN (pow2 (2 * size)) | let two_to_nat_unfold (size:nat) (x:two (natN (pow2 size))) : natN (pow2 (2 * size)) =
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let Mktwo x0 x1 = x in
int_to_natN n2 (x0 + x1 * n1) | {
"file_name": "vale/specs/defs/Vale.Def.Words.Two_s.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 28,
"start_col": 0,
"start_line": 24
} | module Vale.Def.Words.Two_s
open Vale.Def.Words_s
open FStar.Mul
unfold let two_map (#a #b:Type) (f:a -> b) (x:two a) : two b =
let Mktwo x0 x1 = x in
Mktwo (f x0) (f x1)
unfold let two_map2 (#a #b:Type) (f:a -> a -> b) (x y:two a) : two b =
let Mktwo x0 x1 = x in
let Mktwo y0 y1 = y in
Mktwo (f x0 y0) (f x1 y1)
unfold
let nat_to_two_unfold (size:nat) (n:natN (pow2 (2 * size))) : two (natN (pow2 size)) =
let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
Mktwo (n % n1) ((n / n1) % n1)
let nat_to_two (size:nat) (n:natN (pow2 (2 * size))) : two (natN (pow2 size)) =
nat_to_two_unfold size n | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Def.Words.Two_s.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | size: Prims.nat -> x: Vale.Def.Words_s.two (Vale.Def.Words_s.natN (Prims.pow2 size))
-> Vale.Def.Words_s.natN (Prims.pow2 (2 * size)) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words_s.int_to_natN",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pos",
"Vale.Def.Words_s.pow2_norm"
] | [] | false | false | false | false | false | let two_to_nat_unfold (size: nat) (x: two (natN (pow2 size))) : natN (pow2 (2 * size)) =
| let n1 = pow2_norm size in
let n2 = pow2_norm (2 * size) in
let Mktwo x0 x1 = x in
int_to_natN n2 (x0 + x1 * n1) | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.serialize_vlgen | val serialize_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk {sk.parser_kind_subkind == Some ParserStrong})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
: Tot (serializer (parse_vlgen min max pk s)) | val serialize_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk {sk.parser_kind_subkind == Some ParserStrong})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
: Tot (serializer (parse_vlgen min max pk s)) | let serialize_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (serializer (parse_vlgen min max pk s))
= serialize_synth
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
(serialize_bounded_vlgen min max ssk s)
(synth_vlgen_recip min max s)
() | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 6,
"end_line": 416,
"start_col": 0,
"start_line": 400
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len)
inline_for_extraction
let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x
let parse_vlgen_precond
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max
let parse_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t)
= parse_bounded_vlgen min max pk s
`parse_synth`
synth_vlgen min max s
let parse_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
input;
parse_bounded_vlgen_unfold min max pk s input
inline_for_extraction
let synth_bounded_vlgen_payload_recip
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Tot (parse_fldata_strong_t s (U32.v sz))
= x
let serialize_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (serializer (parse_bounded_vlgen_payload min max s sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_serializer (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz) (fun _ -> ())
else
serialize_weaken (parse_bounded_vlgen_payload_kind min max k)
(serialize_synth
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
)
let serialize_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Lemma
(serialize (serialize_bounded_vlgen_payload min max s sz) input == serialize s input)
= serialize_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
input
let serialize_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vlgen min max pk s))
= serialize_tagged_union
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s)
let serialize_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk { sk.parser_kind_subkind == Some ParserStrong } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: parse_bounded_vldata_strong_t min max s)
: Lemma
(serialize (serialize_bounded_vlgen min max ssk s) input == (
let sp = serialize s input in
serialize ssk (U32.uint_to_t (Seq.length sp)) `Seq.append` sp
))
= serialize_tagged_union_eq
ssk
(tag_of_bounded_vlgen_payload min max s)
(serialize_bounded_vlgen_payload min max s)
input;
let tg : bounded_int32 min max = tag_of_bounded_vlgen_payload min max s input in
serialize_bounded_vlgen_payload_unfold min max s tg input
inline_for_extraction
let synth_vlgen_recip
(min: nat)
(max: nat { min <= max } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k } )
(x: t)
: Tot (parse_bounded_vldata_strong_t min max s)
= [@inline_let] let _ =
let sl = Seq.length (serialize s x) in
assert (min <= sl /\ sl <= max)
in
x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296} ->
ssk:
LowParse.Spec.Base.serializer pk
{ Mkparser_kind'?.parser_kind_subkind sk ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->
s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond min max k}
-> LowParse.Spec.Base.serializer (LowParse.Spec.VLGen.parse_vlgen min max pk s) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.VLGen.parse_vlgen_precond",
"LowParse.Spec.Combinators.serialize_synth",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Spec.VLGen.synth_vlgen",
"LowParse.Spec.VLGen.serialize_bounded_vlgen",
"LowParse.Spec.VLGen.synth_vlgen_recip",
"LowParse.Spec.VLGen.parse_vlgen"
] | [] | false | false | false | false | false | let serialize_vlgen
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#sk: parser_kind)
(#pk: parser sk (bounded_int32 min max))
(ssk: serializer pk {sk.parser_kind_subkind == Some ParserStrong})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {parse_vlgen_precond min max k})
: Tot (serializer (parse_vlgen min max pk s)) =
| serialize_synth (parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
(serialize_bounded_vlgen min max ssk s)
(synth_vlgen_recip min max s)
() | false |
LowParse.Spec.VLGen.fst | LowParse.Spec.VLGen.serialize_bounded_vlgen_payload_unfold | val serialize_bounded_vlgen_payload_unfold
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Lemma (serialize (serialize_bounded_vlgen_payload min max s sz) input == serialize s input) | val serialize_bounded_vlgen_payload_unfold
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Lemma (serialize (serialize_bounded_vlgen_payload min max s sz) input == serialize s input) | let serialize_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Lemma
(serialize (serialize_bounded_vlgen_payload min max s sz) input == serialize s input)
= serialize_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
input | {
"file_name": "src/lowparse/LowParse.Spec.VLGen.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 342,
"start_col": 0,
"start_line": 325
} | module LowParse.Spec.VLGen
include LowParse.Spec.Combinators
include LowParse.Spec.AllIntegers
include LowParse.Spec.VLData // for parse_bounded_vldata_strong_t
(* TODO: this module should deprecate and replace LowParse.Spec.VLData *)
module U32 = FStar.UInt32
module Seq = FStar.Seq
let tag_of_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: GTot (bounded_int32 min max)
= U32.uint_to_t (Seq.length (serialize s x))
inline_for_extraction
let synth_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: parse_fldata_strong_t s (U32.v sz))
: Tot (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
= x
inline_for_extraction
let parse_bounded_vlgen_payload_kind
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: Tot parser_kind
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
strong_parser_kind min' max' (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_parser (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
else
weaken (parse_bounded_vlgen_payload_kind min max k)
(parse_fldata_strong s (U32.v sz)
`parse_synth`
synth_bounded_vlgen_payload min max s sz)
let parse_bounded_vlgen_payload_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: bytes)
: Lemma
(parse (parse_bounded_vlgen_payload min max s sz) input == (match parse (parse_fldata_strong s (U32.v sz)) input with
| None -> None
| Some (x, consumed) -> Some (x, consumed)
))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then ()
else
parse_synth_eq
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
input
inline_for_extraction
let parse_bounded_vlgen_kind
(sk: parser_kind)
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
= and_then_kind sk (parse_bounded_vlgen_payload_kind min max k)
let parse_bounded_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vlgen_kind sk min max k) (parse_bounded_vldata_strong_t min max s))
= parse_tagged_union
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
let parse_bounded_vlgen_unfold_aux
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
let input' = Seq.slice input sz (Seq.length input) in
match parse (parse_fldata_strong s (U32.v len)) input' with
| Some (x, consumed_x) ->
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1
let parse_bounded_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: bytes)
: Lemma
(let res = parse (parse_bounded_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_tagged_union_eq
pk
(tag_of_bounded_vlgen_payload min max s)
(parse_bounded_vlgen_payload min max s)
input;
match parse pk input with
| None -> ()
| Some (len, sz) ->
let input1 = Seq.slice input sz (Seq.length input) in
parse_bounded_vlgen_payload_unfold min max s len input1;
if Seq.length input < sz + U32.v len
then ()
else Seq.slice_slice input sz (Seq.length input) 0 (U32.v len)
inline_for_extraction
let synth_vlgen
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: parse_bounded_vldata_strong_t min max s)
: Tot t
= x
let parse_vlgen_precond
(min: nat)
(max: nat { min <= max } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some kmax -> min <= k.parser_kind_low && kmax <= max
let parse_vlgen
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
: Tot (parser (parse_bounded_vlgen_kind sk min max k) t)
= parse_bounded_vlgen min max pk s
`parse_synth`
synth_vlgen min max s
let parse_vlgen_unfold
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#sk: parser_kind)
(pk: parser sk (bounded_int32 min max))
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { parse_vlgen_precond min max k })
(input: bytes)
: Lemma
(let res = parse (parse_vlgen min max pk s) input in
match parse pk input with
| None -> res == None
| Some (len, sz) ->
begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then
Seq.length (serialize s x) = U32.v len /\
res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
)
= parse_synth_eq
(parse_bounded_vlgen min max pk s)
(synth_vlgen min max s)
input;
parse_bounded_vlgen_unfold min max pk s input
inline_for_extraction
let synth_bounded_vlgen_payload_recip
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(x: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Tot (parse_fldata_strong_t s (U32.v sz))
= x
let serialize_bounded_vlgen_payload
(min: nat)
(max: nat { min <= max /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
: Tot (serializer (parse_bounded_vlgen_payload min max s sz))
= let bounds_off =
k.parser_kind_low > U32.v sz || (
match k.parser_kind_high with
| None -> false
| Some kmax -> kmax < U32.v sz
)
in
if bounds_off
then fail_serializer (parse_bounded_vlgen_payload_kind min max k) (refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz) (fun _ -> ())
else
serialize_weaken (parse_bounded_vlgen_payload_kind min max k)
(serialize_synth
(parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.VLData.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLGen.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p ->
sz: LowParse.Spec.BoundedInt.bounded_int32 min max ->
input:
LowParse.Spec.Base.refine_with_tag (LowParse.Spec.VLGen.tag_of_bounded_vlgen_payload min max s
)
sz
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Base.serialize (LowParse.Spec.VLGen.serialize_bounded_vlgen_payload min max s sz
)
input ==
LowParse.Spec.Base.serialize s input) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLGen.tag_of_bounded_vlgen_payload",
"LowParse.Spec.Combinators.serialize_synth_eq",
"LowParse.Spec.FLData.parse_fldata_kind",
"FStar.UInt32.v",
"LowParse.Spec.FLData.parse_fldata_strong_t",
"LowParse.Spec.FLData.parse_fldata_strong",
"LowParse.Spec.VLGen.synth_bounded_vlgen_payload",
"LowParse.Spec.FLData.serialize_fldata_strong",
"LowParse.Spec.VLGen.synth_bounded_vlgen_payload_recip",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.VLGen.parse_bounded_vlgen_payload_kind",
"LowParse.Spec.VLGen.parse_bounded_vlgen_payload",
"LowParse.Spec.VLGen.serialize_bounded_vlgen_payload",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let serialize_bounded_vlgen_payload_unfold
(min: nat)
(max: nat{min <= max /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(sz: bounded_int32 min max)
(input: refine_with_tag (tag_of_bounded_vlgen_payload min max s) sz)
: Lemma (serialize (serialize_bounded_vlgen_payload min max s sz) input == serialize s input) =
| serialize_synth_eq (parse_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload min max s sz)
(serialize_fldata_strong s (U32.v sz))
(synth_bounded_vlgen_payload_recip min max s sz)
()
input | false |