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.C.Types.Array.fsti
Pulse.C.Types.Array.mk_array
val mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td)
val mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td)
let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 24, "end_line": 235, "start_col": 0, "start_line": 234 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Pulse.C.Types.Array.array_ref td -> len: Pulse.C.Types.Array.array_len_t a -> Pulse.C.Types.Array.array td
Prims.Tot
[ "total" ]
[]
[ "Pulse.C.Types.Base.typedef", "Pulse.C.Types.Array.array_ref", "Pulse.C.Types.Array.array_len_t", "Pulse.C.Types.Array.mk_array_or_null", "Pulse.C.Types.Array.array" ]
[]
false
false
false
false
false
let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) =
mk_array_or_null a len
false
Sealed.Plugins.fst
Sealed.Plugins.get_seal_tac
val get_seal_tac (i: int) : Tac (sealed int)
val get_seal_tac (i: int) : Tac (sealed int)
let get_seal_tac (i:int) : Tac (sealed int) = seal (i + 1)
{ "file_name": "examples/native_tactics/Sealed.Plugins.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 12, "start_col": 0, "start_line": 12 }
module Sealed.Plugins open FStar.Sealed open FStar.Tactics.V2 [@@plugin] let use_seal (s:sealed int) : Tac int = unseal s + 1 [@@plugin] let get_seal (i:int) : sealed int = seal (i + 1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Sealed.Plugins.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sealed", "short_module": null }, { "abbrev": false, "full_module": "Sealed", "short_module": null }, { "abbrev": false, "full_module": "Sealed", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.int -> FStar.Tactics.Effect.Tac (FStar.Sealed.sealed Prims.int)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.int", "FStar.Sealed.seal", "Prims.op_Addition", "FStar.Sealed.sealed" ]
[]
false
true
false
false
false
let get_seal_tac (i: int) : Tac (sealed int) =
seal (i + 1)
false
Sealed.Plugins.fst
Sealed.Plugins.get_seal
val get_seal (i: int) : sealed int
val get_seal (i: int) : sealed int
let get_seal (i:int) : sealed int = seal (i + 1)
{ "file_name": "examples/native_tactics/Sealed.Plugins.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 9, "start_col": 0, "start_line": 9 }
module Sealed.Plugins open FStar.Sealed open FStar.Tactics.V2 [@@plugin] let use_seal (s:sealed int) : Tac int = unseal s + 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Sealed.Plugins.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sealed", "short_module": null }, { "abbrev": false, "full_module": "Sealed", "short_module": null }, { "abbrev": false, "full_module": "Sealed", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.int -> FStar.Sealed.sealed Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "FStar.Sealed.seal", "Prims.op_Addition", "FStar.Sealed.sealed" ]
[]
false
false
false
true
false
let get_seal (i: int) : sealed int =
seal (i + 1)
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.full_seq_seq_of_base_array
val full_seq_seq_of_base_array (#t tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))]
val full_seq_seq_of_base_array (#t tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))]
let full_seq_seq_of_base_array (#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))] = assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i))
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 110, "end_line": 530, "start_col": 0, "start_line": 524 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r let seq_of_base_array (#t: Type) (#tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) = Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i)) val ghost_array_of_base_focus (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost unit (pts_to r v ** pure ( has_array_of_base r a )) (fun _ -> array_pts_to a (seq_of_base_array v)) val ghost_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) : stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a }) (pts_to r v) (fun a -> array_pts_to a (seq_of_base_array v)) let array_ref_of_base_post (#t: Type) (#tn: Type0) (#n: Ghost.erased array_size_t) (#td: typedef t) (v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array_ref td) (ar: array td) : GTot prop = array_ptr_of ar == a /\ array_ref_base_size a == Ghost.reveal n /\ array_ref_offset a == 0sz /\ has_array_of_base r ar /\ Ghost.reveal (dsnd ar) == Ghost.reveal n // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) //: STAtomicBase (array_ref td) false opened Unobservable : stt (array_ref td) (pts_to r v) (fun a -> exists* (ar: array td) . array_pts_to ar (seq_of_base_array v) ** pure ( array_ref_of_base_post v r a ar )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) // : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable requires (pts_to r v) returns a: (a: array td { has_array_of_base r a }) ensures (array_pts_to a (seq_of_base_array v)) { let al = array_ref_of_base r; with ga . assert (array_pts_to #t #td ga (seq_of_base_array v)); let a = mk_array_or_null al (Ghost.hide (n <: SZ.t)); rewrite (array_pts_to ga (seq_of_base_array v)) as (array_pts_to a (seq_of_base_array v)); a } ``` val unarray_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost (Ghost.erased (base_array_t t tn n)) (array_pts_to a v ** pure ( has_array_of_base r a )) (fun v' -> pts_to r v' ** pure ( Ghost.reveal v `Seq.equal` seq_of_base_array v' )) val freeable_array (#t: Type) (#td: typedef t) (a: array td) : Tot vprop let freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop = if g_array_is_null a then emp else freeable_array a [@@noextract_to "krml"] // primitive val array_ptr_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) : stt (array_ptr td) emp (fun a -> exists* (ar: array_or_null td) (s: Seq.seq t) . freeable_or_null_array ar ** array_pts_to_or_null ar s ** pure ( array_ptr_of ar == a /\ (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s `Seq.equal` FStar.Seq.create (SZ.v sz) (uninitialized td) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) requires emp returns ar: array_or_null td ensures ( freeable_or_null_array ar ** ( exists* s . array_pts_to_or_null ar s ** pure ( (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s == FStar.Seq.create (SZ.v sz) (uninitialized td) ))) { let a : array_ptr td = array_ptr_alloc td sz; with ar' s . assert (freeable_or_null_array ar' ** array_pts_to_or_null #_ #td ar' s); let len: array_len_t a = array_len_of ar'; let ar = mk_array_or_null a len; rewrite (array_pts_to_or_null ar' s) as (array_pts_to_or_null ar s); rewrite (freeable_or_null_array ar') as (freeable_or_null_array ar); ar } ``` let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop = forall (i: nat { i < Seq.length v }) . {:pattern (Seq.index v i)} full td (Seq.index v i)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
tn: Type0 -> td: Pulse.C.Types.Base.typedef t -> b: Pulse.C.Types.Array.base_array_t t tn n -> FStar.Pervasives.Lemma (ensures Pulse.C.Types.Array.full_seq td (Pulse.C.Types.Array.seq_of_base_array b) <==> Pulse.C.Types.Base.full (Pulse.C.Types.Array.base_array0 tn td n) b) [SMTPat (Pulse.C.Types.Array.full_seq td (Pulse.C.Types.Array.seq_of_base_array b))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Pulse.C.Types.Base.typedef", "Pulse.C.Types.Array.array_size_t", "Pulse.C.Types.Array.base_array_t", "Prims._assert", "Prims.l_Forall", "Pulse.C.Types.Array.base_array_index_t", "Prims.eq2", "Pulse.C.Types.Array.base_array_index", "FStar.Seq.Base.index", "Pulse.C.Types.Array.seq_of_base_array", "FStar.SizeT.v", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "Pulse.C.Types.Array.full_seq", "Pulse.C.Types.Base.full", "Pulse.C.Types.Array.base_array0", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.prop", "Prims.Nil" ]
[]
false
false
true
false
false
let full_seq_seq_of_base_array (#t tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))] =
assert (forall (i: base_array_index_t n). base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i))
false
DM4F_layered.fst
DM4F_layered.st_monotonic
val st_monotonic (#st #a: _) (w: wp0 st a) : Type0
val st_monotonic (#st #a: _) (w: wp0 st a) : Type0
let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 77, "end_line": 35, "start_col": 0, "start_line": 32 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
w: DM4F_layered.wp0 st a -> Type0
Prims.Tot
[ "total" ]
[]
[ "DM4F_layered.wp0", "Prims.l_Forall", "Prims.logical", "Prims.l_imp" ]
[]
false
false
false
true
true
let st_monotonic #st #a (w: wp0 st a) : Type0 =
forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.has_array_of_base_inj
val has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires (has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2)) (ensures (a1 == a2))
val has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires (has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2)) (ensures (a1 == a2))
let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 50, "end_line": 347, "start_col": 0, "start_line": 332 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Pulse.C.Types.Base.ref (Pulse.C.Types.Array.base_array0 tn td n) -> a1: Pulse.C.Types.Array.array td -> a2: Pulse.C.Types.Array.array td -> FStar.Pervasives.Lemma (requires Pulse.C.Types.Array.has_array_of_base r a1 /\ Pulse.C.Types.Array.has_array_of_base r a2) (ensures a1 == a2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Pulse.C.Types.Array.array_size_t", "Pulse.C.Types.Base.typedef", "Pulse.C.Types.Base.ref", "Pulse.C.Types.Array.base_array_t", "Pulse.C.Types.Array.base_array0", "Pulse.C.Types.Array.array", "Pulse.C.Types.Array.array_ptr", "Pulse.C.Types.Array.array_len_t", "Pulse.C.Types.Array.array_ref_base_offset_inj", "Prims.unit", "Prims.l_and", "Pulse.C.Types.Array.has_array_of_base", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires (has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2)) (ensures (a1 == a2)) =
let (| ar1 , _ |) = a1 in let (| ar2 , _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.array_ref_of
val array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td)
val array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td)
let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 17, "end_line": 231, "start_col": 0, "start_line": 230 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false })
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
ar: Pulse.C.Types.Array.array td -> Pulse.C.Types.Array.array_ref td
Prims.Tot
[ "total" ]
[]
[ "Pulse.C.Types.Base.typedef", "Pulse.C.Types.Array.array", "Pulse.C.Types.Array.array_ptr_of", "Pulse.C.Types.Array.array_ref" ]
[]
false
false
false
false
false
let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) =
array_ptr_of ar
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.has_array_of_base
val has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop
val has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop
let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 330, "start_col": 0, "start_line": 318 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits"
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Pulse.C.Types.Base.ref (Pulse.C.Types.Array.base_array0 tn td n) -> a: Pulse.C.Types.Array.array td -> Prims.GTot Prims.prop
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.C.Types.Array.array_size_t", "Pulse.C.Types.Base.typedef", "Pulse.C.Types.Base.ref", "Pulse.C.Types.Array.base_array_t", "Pulse.C.Types.Array.base_array0", "Pulse.C.Types.Array.array", "Pulse.C.Types.Array.array_ptr", "Pulse.C.Types.Array.array_len_t", "Prims.l_and", "Prims.eq2", "FStar.SizeT.t", "Pulse.C.Types.Array.array_ref_base_size", "Pulse.C.Types.Array.has_array_ref_base", "Pulse.C.Types.Array.array_ref_offset", "FStar.SizeT.__uint_to_t", "FStar.Ghost.reveal", "Prims.prop" ]
[]
false
false
false
false
true
let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop =
let (| al , len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n
false
Sealed.Plugins.fst
Sealed.Plugins.use_seal
val use_seal (s: sealed int) : Tac int
val use_seal (s: sealed int) : Tac int
let use_seal (s:sealed int) : Tac int = unseal s + 1
{ "file_name": "examples/native_tactics/Sealed.Plugins.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 6, "start_col": 0, "start_line": 6 }
module Sealed.Plugins open FStar.Sealed open FStar.Tactics.V2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Sealed.Plugins.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sealed", "short_module": null }, { "abbrev": false, "full_module": "Sealed", "short_module": null }, { "abbrev": false, "full_module": "Sealed", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Sealed.sealed Prims.int -> FStar.Tactics.Effect.Tac Prims.int
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Sealed.sealed", "Prims.int", "Prims.op_Addition", "FStar.Tactics.Unseal.unseal" ]
[]
false
true
false
false
false
let use_seal (s: sealed int) : Tac int =
unseal s + 1
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.array_pts_to_or_null
val array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop
val array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop
let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 23, "end_line": 259, "start_col": 0, "start_line": 251 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Pulse.C.Types.Array.array_or_null td -> v: FStar.Ghost.erased (FStar.Seq.Base.seq t) -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Pulse.C.Types.Base.typedef", "Pulse.C.Types.Array.array_or_null", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Pulse.C.Types.Array.g_array_is_null", "Pulse.Lib.Core.emp", "Prims.bool", "Pulse.C.Types.Array.array_pts_to", "Pulse.Lib.Core.vprop" ]
[]
false
false
false
false
false
let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop =
if g_array_is_null r then emp else array_pts_to r v
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.seq_of_base_array
val seq_of_base_array (#t #tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n))
val seq_of_base_array (#t #tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n))
let seq_of_base_array (#t: Type) (#tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) = Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i))
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 72, "end_line": 355, "start_col": 0, "start_line": 349 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.C.Types.Array.base_array_t t tn n -> Prims.GTot (FStar.Seq.Properties.lseq t (FStar.SizeT.v n))
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.C.Types.Array.array_size_t", "Pulse.C.Types.Array.base_array_t", "FStar.Seq.Base.init_ghost", "FStar.SizeT.v", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.C.Types.Array.base_array_index", "FStar.SizeT.uint_to_t", "FStar.Seq.Properties.lseq" ]
[]
false
false
false
false
false
let seq_of_base_array (#t #tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) =
Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i))
false
ExtractRefs.fst
ExtractRefs.main_ref
val main_ref: Prims.unit -> Steel U32.t emp (fun _ -> emp) (requires fun _ -> True) (ensures fun _ x _ -> x == 2ul)
val main_ref: Prims.unit -> Steel U32.t emp (fun _ -> emp) (requires fun _ -> True) (ensures fun _ x _ -> x == 2ul)
let main_ref () : Steel U32.t emp (fun _ -> emp) (requires fun _ -> True) (ensures fun _ x _ -> x == 2ul) = // Allocating reference r let r = malloc 0ul in // Writing value 2 in the newly allocated reference write r 2ul; // Reading value of r in memory. This was set to 2 just above let v = read r in // Freeing reference r free r; // The returned value is equal to 1, the context is now empty v
{ "file_name": "share/steel/tutorial/ExtractRefs.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 44, "start_col": 0, "start_line": 32 }
module ExtractRefs open FStar.Ghost open Steel.FractionalPermission open Steel.Effect.Atomic open Steel.Effect open Steel.Reference module U32 = FStar.UInt32 /// Some examples using Steel references with fractional permissions #push-options "--fuel 0 --ifuel 0 --ide_id_info_off" (** Swap examples **) /// A selector version of swap, more idiomatic in Steel let swap (r1 r2:ref U32.t) : Steel unit (vptr r1 `star` vptr r2) (fun _ -> vptr r1 `star` vptr r2) (requires fun _ -> True) (ensures fun h0 _ h1 -> sel r1 h0 == sel r2 h1 /\ sel r2 h0 == sel r1 h1) = let x1 = read r1 in let x2 = read r2 in write r2 x1; write r1 x2 (** Allocating and Freeing references *)
{ "checked_file": "/", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ExtractRefs.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Steel.Effect.Steel FStar.UInt32.t
Steel.Effect.Steel
[]
[]
[ "Prims.unit", "FStar.UInt32.t", "Steel.Reference.free", "Steel.Reference.read", "Steel.Reference.write", "FStar.UInt32.__uint_to_t", "Steel.Reference.ref", "Steel.Reference.malloc", "Steel.Effect.Common.emp", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True", "Prims.eq2" ]
[]
false
true
false
false
false
let main_ref () : Steel U32.t emp (fun _ -> emp) (requires fun _ -> True) (ensures fun _ x _ -> x == 2ul) =
let r = malloc 0ul in write r 2ul; let v = read r in free r; v
false
DM4F_layered.fst
DM4F_layered.stronger
val stronger (#a: Type) (#st: Type0) (w1 w2: wp st a) : Type0
val stronger (#a: Type) (#st: Type0) (w1 w2: wp st a) : Type0
let stronger (#a:Type) (#st:Type0) (w1 w2 : wp st a) : Type0 = forall s0 p. w1 s0 p ==> w2 s0 p
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 105, "start_col": 0, "start_line": 101 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); } let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1 let ite_wp #a #st (b:bool) (w1 w2 : wp st a) : wp st a = fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p) let if_then_else (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) (g : repr a st wpg) (b : bool) : Type = repr a st (ite_wp b wpf wpg)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
w1: DM4F_layered.wp st a -> w2: DM4F_layered.wp st a -> Type0
Prims.Tot
[ "total" ]
[]
[ "DM4F_layered.wp", "Prims.l_Forall", "DM4F_layered.post_t", "Prims.l_imp" ]
[]
false
false
false
true
true
let stronger (#a: Type) (#st: Type0) (w1 w2: wp st a) : Type0 =
forall s0 p. w1 s0 p ==> w2 s0 p
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.freeable_or_null_array
val freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop
val freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop
let freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop = if g_array_is_null a then emp else freeable_array a
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 23, "end_line": 473, "start_col": 0, "start_line": 466 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r let seq_of_base_array (#t: Type) (#tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) = Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i)) val ghost_array_of_base_focus (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost unit (pts_to r v ** pure ( has_array_of_base r a )) (fun _ -> array_pts_to a (seq_of_base_array v)) val ghost_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) : stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a }) (pts_to r v) (fun a -> array_pts_to a (seq_of_base_array v)) let array_ref_of_base_post (#t: Type) (#tn: Type0) (#n: Ghost.erased array_size_t) (#td: typedef t) (v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array_ref td) (ar: array td) : GTot prop = array_ptr_of ar == a /\ array_ref_base_size a == Ghost.reveal n /\ array_ref_offset a == 0sz /\ has_array_of_base r ar /\ Ghost.reveal (dsnd ar) == Ghost.reveal n // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) //: STAtomicBase (array_ref td) false opened Unobservable : stt (array_ref td) (pts_to r v) (fun a -> exists* (ar: array td) . array_pts_to ar (seq_of_base_array v) ** pure ( array_ref_of_base_post v r a ar )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) // : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable requires (pts_to r v) returns a: (a: array td { has_array_of_base r a }) ensures (array_pts_to a (seq_of_base_array v)) { let al = array_ref_of_base r; with ga . assert (array_pts_to #t #td ga (seq_of_base_array v)); let a = mk_array_or_null al (Ghost.hide (n <: SZ.t)); rewrite (array_pts_to ga (seq_of_base_array v)) as (array_pts_to a (seq_of_base_array v)); a } ``` val unarray_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost (Ghost.erased (base_array_t t tn n)) (array_pts_to a v ** pure ( has_array_of_base r a )) (fun v' -> pts_to r v' ** pure ( Ghost.reveal v `Seq.equal` seq_of_base_array v' )) val freeable_array (#t: Type) (#td: typedef t) (a: array td) : Tot vprop
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Pulse.C.Types.Array.array_or_null td -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Pulse.C.Types.Base.typedef", "Pulse.C.Types.Array.array_or_null", "Pulse.C.Types.Array.g_array_is_null", "Pulse.Lib.Core.emp", "Prims.bool", "Pulse.C.Types.Array.freeable_array", "Pulse.Lib.Core.vprop" ]
[]
false
false
false
false
false
let freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop =
if g_array_is_null a then emp else freeable_array a
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.array_split_l
val array_split_l (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Pure (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True))
val array_split_l (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Pure (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True))
let array_split_l (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Pure (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, _ |) = a in (| al, Ghost.hide i |)
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 24, "end_line": 870, "start_col": 0, "start_line": 861 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r let seq_of_base_array (#t: Type) (#tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) = Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i)) val ghost_array_of_base_focus (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost unit (pts_to r v ** pure ( has_array_of_base r a )) (fun _ -> array_pts_to a (seq_of_base_array v)) val ghost_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) : stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a }) (pts_to r v) (fun a -> array_pts_to a (seq_of_base_array v)) let array_ref_of_base_post (#t: Type) (#tn: Type0) (#n: Ghost.erased array_size_t) (#td: typedef t) (v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array_ref td) (ar: array td) : GTot prop = array_ptr_of ar == a /\ array_ref_base_size a == Ghost.reveal n /\ array_ref_offset a == 0sz /\ has_array_of_base r ar /\ Ghost.reveal (dsnd ar) == Ghost.reveal n // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) //: STAtomicBase (array_ref td) false opened Unobservable : stt (array_ref td) (pts_to r v) (fun a -> exists* (ar: array td) . array_pts_to ar (seq_of_base_array v) ** pure ( array_ref_of_base_post v r a ar )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) // : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable requires (pts_to r v) returns a: (a: array td { has_array_of_base r a }) ensures (array_pts_to a (seq_of_base_array v)) { let al = array_ref_of_base r; with ga . assert (array_pts_to #t #td ga (seq_of_base_array v)); let a = mk_array_or_null al (Ghost.hide (n <: SZ.t)); rewrite (array_pts_to ga (seq_of_base_array v)) as (array_pts_to a (seq_of_base_array v)); a } ``` val unarray_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost (Ghost.erased (base_array_t t tn n)) (array_pts_to a v ** pure ( has_array_of_base r a )) (fun v' -> pts_to r v' ** pure ( Ghost.reveal v `Seq.equal` seq_of_base_array v' )) val freeable_array (#t: Type) (#td: typedef t) (a: array td) : Tot vprop let freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop = if g_array_is_null a then emp else freeable_array a [@@noextract_to "krml"] // primitive val array_ptr_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) : stt (array_ptr td) emp (fun a -> exists* (ar: array_or_null td) (s: Seq.seq t) . freeable_or_null_array ar ** array_pts_to_or_null ar s ** pure ( array_ptr_of ar == a /\ (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s `Seq.equal` FStar.Seq.create (SZ.v sz) (uninitialized td) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) requires emp returns ar: array_or_null td ensures ( freeable_or_null_array ar ** ( exists* s . array_pts_to_or_null ar s ** pure ( (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s == FStar.Seq.create (SZ.v sz) (uninitialized td) ))) { let a : array_ptr td = array_ptr_alloc td sz; with ar' s . assert (freeable_or_null_array ar' ** array_pts_to_or_null #_ #td ar' s); let len: array_len_t a = array_len_of ar'; let ar = mk_array_or_null a len; rewrite (array_pts_to_or_null ar' s) as (array_pts_to_or_null ar s); rewrite (freeable_or_null_array ar') as (freeable_or_null_array ar); ar } ``` let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop = forall (i: nat { i < Seq.length v }) . {:pattern (Seq.index v i)} full td (Seq.index v i) let full_seq_seq_of_base_array (#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))] = assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i)) [@@noextract_to "krml"] // primitive val array_ref_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (n: array_len_t a) : stt unit (freeable_array (mk_array a n) ** array_pts_to (mk_array a n) s ** pure ( full_seq td s )) (fun _ -> emp) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) requires (freeable_array a ** array_pts_to a s ** pure ( full_seq td s )) ensures emp { let al = array_ptr_of a; let n: array_len_t al = array_len_of a; rewrite (freeable_array a) as (freeable_array (mk_array al n)); rewrite (array_pts_to a s) as (array_pts_to (mk_array al n) s); array_ref_free al n } ``` (* val has_array_of_ref (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : Tot vprop val has_array_of_ref_post (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : STGhost unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a) (True) (fun _ -> let (| al, len |) = a in array_ref_base_size al == 1sz /\ array_ref_offset al == 0sz /\ Ghost.reveal len == 1sz ) // val has_array_of_ref_inj // (#t: Type) // (#td: typedef t) // (r: ref td) // (a1 a2: array td) // : Lemma // (requires ( // has_array_of_ref r a1 /\ // has_array_of_ref r a2 // )) // (ensures a1 == a2) val ghost_array_of_ref_focus (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) (a: array td) : stt_ghost unit opened (pts_to r v ** has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** array_pts_to a (Seq.create 1 (Ghost.reveal v))) val ghost_array_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt_ghost (Ghost.erased (array td)) opened (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (a: array_ref td { array_ref_base_size a == 1sz /\ array_ref_offset a == 0sz }) (pts_to r v) (fun a -> array_pts_to (| a, Ghost.hide 1sz |) (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r (| a, Ghost.hide 1sz |)) inline_for_extraction [@@noextract_to "krml"] let array_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (array td) (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) = let al = array_ref_of_ref r in let a : array td = (| al, Ghost.hide 1sz |) in rewrite (array_pts_to _ _) (array_pts_to _ _); rewrite (has_array_of_ref _ _) (has_array_of_ref r a); return a val unarray_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (r: ref td) (a: array td) : stt_ghost (squash (Seq.length s == 1)) opened (array_pts_to a s ** has_array_of_ref r a) (fun _ -> pts_to r (Seq.index s 0) ** has_array_of_ref r a) *) val has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) : Tot vprop (* = SZ.v i < SZ.v (dsnd a) /\ has_base_array_cell (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r *) val has_array_cell_post (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r': ref td) : stt_ghost unit (has_array_cell a i r') (fun _ -> has_array_cell a i r' ** pure ( SZ.v i < SZ.v (dsnd a) )) val has_array_cell_has_base_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_array_cell a i r ** pure ( has_array_ref_base (array_ptr_of a) br )) (fun j -> has_base_array_cell br j r ** pure ( SZ.v j == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v i )) val has_base_array_cell_has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_base_array_cell br i r ** pure ( has_array_ref_base (array_ptr_of a) br /\ SZ.v i >= SZ.v (array_ref_offset (array_ptr_of a)) /\ SZ.v i < SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v (dsnd a) )) (fun j -> has_array_cell a j r ** pure ( SZ.v i == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v j )) val has_array_cell_inj (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit ( has_array_cell a i r1 ** has_array_cell a i r2 ) (fun _ -> has_array_cell a i r1 ** has_array_cell a i r2 ** ref_equiv r1 r2 ) // = has_base_array_cell_inj (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r1 r2 (* val has_array_cell_array_of_ref (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : SteelGhostT unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** has_array_cell a 0sz r) *) val ghost_array_cell_focus (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** has_array_cell a i r) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) val ghost_array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (r: Ghost.erased (ref td) { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) (fun r -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) [@@noextract_to "krml"] // primitive val array_ref_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (len: array_len_t a) (i: SZ.t) : stt (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v len }) (array_pts_to (mk_array a len) s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v len )) (fun r -> array_pts_to (mk_array a len) (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell (mk_array a len) i r) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) requires (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) returns r: (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) ensures (array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let r = array_ref_cell al len i; rewrite (array_pts_to (mk_array al len) (Seq.upd s (SZ.v i) (unknown td))) as (array_pts_to a (Seq.upd s (SZ.v i) (unknown td))); rewrite (has_array_cell (mk_array al len) i r) as (has_array_cell a i r); r } ``` val unarray_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (#v: Ghost.erased t) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pts_to r v ** has_array_cell a i r ** pure ( SZ.v i < Seq.length s ==> Seq.index s (SZ.v i) == unknown td )) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) v) ** has_array_cell a i r) val array_ref_shift (#t: Type) (#td: typedef t) (a: array_ref td) (i: SZ.t) : Ghost (array_ref td) (requires (SZ.v (array_ref_offset a) + SZ.v i <= SZ.v (array_ref_base_size a))) (ensures (fun y -> array_ref_base_size y == array_ref_base_size a /\ (forall ty r . has_array_ref_base a #ty r ==> has_array_ref_base y #ty (coerce_eq () r)) /\ array_ref_offset y == array_ref_offset a `SZ.add` i )) val array_ref_shift_zero (#t: Type) (#td: typedef t) (a: array_ref td) : Lemma (ensures ( array_ref_shift a 0sz == a )) val array_ref_shift_assoc (#t: Type) (#td: typedef t) (a: array_ref td) (i1 i2: SZ.t) : Lemma (requires (SZ.v (array_ref_offset a) + SZ.v i1 + SZ.v i2 <= SZ.v (array_ref_base_size a))) (ensures ( array_ref_shift a (SZ.add i1 i2) == array_ref_shift (array_ref_shift a i1) i2 ))
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Pulse.C.Types.Array.array td -> i: FStar.SizeT.t -> Prims.Pure (Pulse.C.Types.Array.array td)
Prims.Pure
[]
[]
[ "Pulse.C.Types.Base.typedef", "Pulse.C.Types.Array.array", "FStar.SizeT.t", "Pulse.C.Types.Array.array_ptr", "Pulse.C.Types.Array.array_len_t", "Prims.Mkdtuple2", "FStar.Ghost.hide", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.SizeT.v", "FStar.Ghost.reveal", "FStar.Pervasives.dsnd", "Prims.l_True" ]
[]
false
false
false
false
false
let array_split_l (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Pure (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) =
let (| al , _ |) = a in (| al, Ghost.hide i |)
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.array_split_r
val array_split_r (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Ghost (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True))
val array_split_r (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Ghost (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True))
let array_split_r (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Ghost (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, len |) = a in (| array_ref_shift al i, Ghost.hide (len `SZ.sub` i) |)
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 57, "end_line": 881, "start_col": 0, "start_line": 872 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r let seq_of_base_array (#t: Type) (#tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) = Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i)) val ghost_array_of_base_focus (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost unit (pts_to r v ** pure ( has_array_of_base r a )) (fun _ -> array_pts_to a (seq_of_base_array v)) val ghost_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) : stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a }) (pts_to r v) (fun a -> array_pts_to a (seq_of_base_array v)) let array_ref_of_base_post (#t: Type) (#tn: Type0) (#n: Ghost.erased array_size_t) (#td: typedef t) (v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array_ref td) (ar: array td) : GTot prop = array_ptr_of ar == a /\ array_ref_base_size a == Ghost.reveal n /\ array_ref_offset a == 0sz /\ has_array_of_base r ar /\ Ghost.reveal (dsnd ar) == Ghost.reveal n // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) //: STAtomicBase (array_ref td) false opened Unobservable : stt (array_ref td) (pts_to r v) (fun a -> exists* (ar: array td) . array_pts_to ar (seq_of_base_array v) ** pure ( array_ref_of_base_post v r a ar )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) // : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable requires (pts_to r v) returns a: (a: array td { has_array_of_base r a }) ensures (array_pts_to a (seq_of_base_array v)) { let al = array_ref_of_base r; with ga . assert (array_pts_to #t #td ga (seq_of_base_array v)); let a = mk_array_or_null al (Ghost.hide (n <: SZ.t)); rewrite (array_pts_to ga (seq_of_base_array v)) as (array_pts_to a (seq_of_base_array v)); a } ``` val unarray_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost (Ghost.erased (base_array_t t tn n)) (array_pts_to a v ** pure ( has_array_of_base r a )) (fun v' -> pts_to r v' ** pure ( Ghost.reveal v `Seq.equal` seq_of_base_array v' )) val freeable_array (#t: Type) (#td: typedef t) (a: array td) : Tot vprop let freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop = if g_array_is_null a then emp else freeable_array a [@@noextract_to "krml"] // primitive val array_ptr_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) : stt (array_ptr td) emp (fun a -> exists* (ar: array_or_null td) (s: Seq.seq t) . freeable_or_null_array ar ** array_pts_to_or_null ar s ** pure ( array_ptr_of ar == a /\ (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s `Seq.equal` FStar.Seq.create (SZ.v sz) (uninitialized td) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) requires emp returns ar: array_or_null td ensures ( freeable_or_null_array ar ** ( exists* s . array_pts_to_or_null ar s ** pure ( (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s == FStar.Seq.create (SZ.v sz) (uninitialized td) ))) { let a : array_ptr td = array_ptr_alloc td sz; with ar' s . assert (freeable_or_null_array ar' ** array_pts_to_or_null #_ #td ar' s); let len: array_len_t a = array_len_of ar'; let ar = mk_array_or_null a len; rewrite (array_pts_to_or_null ar' s) as (array_pts_to_or_null ar s); rewrite (freeable_or_null_array ar') as (freeable_or_null_array ar); ar } ``` let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop = forall (i: nat { i < Seq.length v }) . {:pattern (Seq.index v i)} full td (Seq.index v i) let full_seq_seq_of_base_array (#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))] = assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i)) [@@noextract_to "krml"] // primitive val array_ref_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (n: array_len_t a) : stt unit (freeable_array (mk_array a n) ** array_pts_to (mk_array a n) s ** pure ( full_seq td s )) (fun _ -> emp) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) requires (freeable_array a ** array_pts_to a s ** pure ( full_seq td s )) ensures emp { let al = array_ptr_of a; let n: array_len_t al = array_len_of a; rewrite (freeable_array a) as (freeable_array (mk_array al n)); rewrite (array_pts_to a s) as (array_pts_to (mk_array al n) s); array_ref_free al n } ``` (* val has_array_of_ref (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : Tot vprop val has_array_of_ref_post (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : STGhost unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a) (True) (fun _ -> let (| al, len |) = a in array_ref_base_size al == 1sz /\ array_ref_offset al == 0sz /\ Ghost.reveal len == 1sz ) // val has_array_of_ref_inj // (#t: Type) // (#td: typedef t) // (r: ref td) // (a1 a2: array td) // : Lemma // (requires ( // has_array_of_ref r a1 /\ // has_array_of_ref r a2 // )) // (ensures a1 == a2) val ghost_array_of_ref_focus (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) (a: array td) : stt_ghost unit opened (pts_to r v ** has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** array_pts_to a (Seq.create 1 (Ghost.reveal v))) val ghost_array_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt_ghost (Ghost.erased (array td)) opened (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (a: array_ref td { array_ref_base_size a == 1sz /\ array_ref_offset a == 0sz }) (pts_to r v) (fun a -> array_pts_to (| a, Ghost.hide 1sz |) (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r (| a, Ghost.hide 1sz |)) inline_for_extraction [@@noextract_to "krml"] let array_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (array td) (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) = let al = array_ref_of_ref r in let a : array td = (| al, Ghost.hide 1sz |) in rewrite (array_pts_to _ _) (array_pts_to _ _); rewrite (has_array_of_ref _ _) (has_array_of_ref r a); return a val unarray_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (r: ref td) (a: array td) : stt_ghost (squash (Seq.length s == 1)) opened (array_pts_to a s ** has_array_of_ref r a) (fun _ -> pts_to r (Seq.index s 0) ** has_array_of_ref r a) *) val has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) : Tot vprop (* = SZ.v i < SZ.v (dsnd a) /\ has_base_array_cell (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r *) val has_array_cell_post (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r': ref td) : stt_ghost unit (has_array_cell a i r') (fun _ -> has_array_cell a i r' ** pure ( SZ.v i < SZ.v (dsnd a) )) val has_array_cell_has_base_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_array_cell a i r ** pure ( has_array_ref_base (array_ptr_of a) br )) (fun j -> has_base_array_cell br j r ** pure ( SZ.v j == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v i )) val has_base_array_cell_has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_base_array_cell br i r ** pure ( has_array_ref_base (array_ptr_of a) br /\ SZ.v i >= SZ.v (array_ref_offset (array_ptr_of a)) /\ SZ.v i < SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v (dsnd a) )) (fun j -> has_array_cell a j r ** pure ( SZ.v i == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v j )) val has_array_cell_inj (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit ( has_array_cell a i r1 ** has_array_cell a i r2 ) (fun _ -> has_array_cell a i r1 ** has_array_cell a i r2 ** ref_equiv r1 r2 ) // = has_base_array_cell_inj (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r1 r2 (* val has_array_cell_array_of_ref (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : SteelGhostT unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** has_array_cell a 0sz r) *) val ghost_array_cell_focus (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** has_array_cell a i r) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) val ghost_array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (r: Ghost.erased (ref td) { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) (fun r -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) [@@noextract_to "krml"] // primitive val array_ref_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (len: array_len_t a) (i: SZ.t) : stt (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v len }) (array_pts_to (mk_array a len) s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v len )) (fun r -> array_pts_to (mk_array a len) (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell (mk_array a len) i r) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) requires (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) returns r: (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) ensures (array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let r = array_ref_cell al len i; rewrite (array_pts_to (mk_array al len) (Seq.upd s (SZ.v i) (unknown td))) as (array_pts_to a (Seq.upd s (SZ.v i) (unknown td))); rewrite (has_array_cell (mk_array al len) i r) as (has_array_cell a i r); r } ``` val unarray_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (#v: Ghost.erased t) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pts_to r v ** has_array_cell a i r ** pure ( SZ.v i < Seq.length s ==> Seq.index s (SZ.v i) == unknown td )) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) v) ** has_array_cell a i r) val array_ref_shift (#t: Type) (#td: typedef t) (a: array_ref td) (i: SZ.t) : Ghost (array_ref td) (requires (SZ.v (array_ref_offset a) + SZ.v i <= SZ.v (array_ref_base_size a))) (ensures (fun y -> array_ref_base_size y == array_ref_base_size a /\ (forall ty r . has_array_ref_base a #ty r ==> has_array_ref_base y #ty (coerce_eq () r)) /\ array_ref_offset y == array_ref_offset a `SZ.add` i )) val array_ref_shift_zero (#t: Type) (#td: typedef t) (a: array_ref td) : Lemma (ensures ( array_ref_shift a 0sz == a )) val array_ref_shift_assoc (#t: Type) (#td: typedef t) (a: array_ref td) (i1 i2: SZ.t) : Lemma (requires (SZ.v (array_ref_offset a) + SZ.v i1 + SZ.v i2 <= SZ.v (array_ref_base_size a))) (ensures ( array_ref_shift a (SZ.add i1 i2) == array_ref_shift (array_ref_shift a i1) i2 )) inline_for_extraction [@@noextract_to "krml"] let array_split_l (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Pure (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, _ |) = a in (| al, Ghost.hide i |)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Pulse.C.Types.Array.array td -> i: FStar.SizeT.t -> Prims.Ghost (Pulse.C.Types.Array.array td)
Prims.Ghost
[]
[]
[ "Pulse.C.Types.Base.typedef", "Pulse.C.Types.Array.array", "FStar.SizeT.t", "Pulse.C.Types.Array.array_ptr", "Pulse.C.Types.Array.array_len_t", "Prims.Mkdtuple2", "Pulse.C.Types.Array.array_ref_shift", "FStar.Ghost.hide", "FStar.SizeT.sub", "FStar.Ghost.reveal", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.SizeT.v", "FStar.Pervasives.dsnd", "Prims.l_True" ]
[]
false
false
false
false
false
let array_split_r (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Ghost (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) =
let (| al , len |) = a in (| array_ref_shift al i, Ghost.hide (len `SZ.sub` i) |)
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.fractionable_seq_seq_of_base_array
val fractionable_seq_seq_of_base_array (#t tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (fractionable_seq td (seq_of_base_array b) <==> fractionable (base_array0 tn td n) b) ) [SMTPat (fractionable_seq td (seq_of_base_array b))]
val fractionable_seq_seq_of_base_array (#t tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (fractionable_seq td (seq_of_base_array b) <==> fractionable (base_array0 tn td n) b) ) [SMTPat (fractionable_seq td (seq_of_base_array b))]
let fractionable_seq_seq_of_base_array (#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (fractionable_seq td (seq_of_base_array b) <==> fractionable (base_array0 tn td n) b)) [SMTPat (fractionable_seq td (seq_of_base_array b))] = assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i))
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 110, "end_line": 1041, "start_col": 0, "start_line": 1035 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r let seq_of_base_array (#t: Type) (#tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) = Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i)) val ghost_array_of_base_focus (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost unit (pts_to r v ** pure ( has_array_of_base r a )) (fun _ -> array_pts_to a (seq_of_base_array v)) val ghost_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) : stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a }) (pts_to r v) (fun a -> array_pts_to a (seq_of_base_array v)) let array_ref_of_base_post (#t: Type) (#tn: Type0) (#n: Ghost.erased array_size_t) (#td: typedef t) (v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array_ref td) (ar: array td) : GTot prop = array_ptr_of ar == a /\ array_ref_base_size a == Ghost.reveal n /\ array_ref_offset a == 0sz /\ has_array_of_base r ar /\ Ghost.reveal (dsnd ar) == Ghost.reveal n // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) //: STAtomicBase (array_ref td) false opened Unobservable : stt (array_ref td) (pts_to r v) (fun a -> exists* (ar: array td) . array_pts_to ar (seq_of_base_array v) ** pure ( array_ref_of_base_post v r a ar )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) // : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable requires (pts_to r v) returns a: (a: array td { has_array_of_base r a }) ensures (array_pts_to a (seq_of_base_array v)) { let al = array_ref_of_base r; with ga . assert (array_pts_to #t #td ga (seq_of_base_array v)); let a = mk_array_or_null al (Ghost.hide (n <: SZ.t)); rewrite (array_pts_to ga (seq_of_base_array v)) as (array_pts_to a (seq_of_base_array v)); a } ``` val unarray_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost (Ghost.erased (base_array_t t tn n)) (array_pts_to a v ** pure ( has_array_of_base r a )) (fun v' -> pts_to r v' ** pure ( Ghost.reveal v `Seq.equal` seq_of_base_array v' )) val freeable_array (#t: Type) (#td: typedef t) (a: array td) : Tot vprop let freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop = if g_array_is_null a then emp else freeable_array a [@@noextract_to "krml"] // primitive val array_ptr_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) : stt (array_ptr td) emp (fun a -> exists* (ar: array_or_null td) (s: Seq.seq t) . freeable_or_null_array ar ** array_pts_to_or_null ar s ** pure ( array_ptr_of ar == a /\ (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s `Seq.equal` FStar.Seq.create (SZ.v sz) (uninitialized td) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) requires emp returns ar: array_or_null td ensures ( freeable_or_null_array ar ** ( exists* s . array_pts_to_or_null ar s ** pure ( (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s == FStar.Seq.create (SZ.v sz) (uninitialized td) ))) { let a : array_ptr td = array_ptr_alloc td sz; with ar' s . assert (freeable_or_null_array ar' ** array_pts_to_or_null #_ #td ar' s); let len: array_len_t a = array_len_of ar'; let ar = mk_array_or_null a len; rewrite (array_pts_to_or_null ar' s) as (array_pts_to_or_null ar s); rewrite (freeable_or_null_array ar') as (freeable_or_null_array ar); ar } ``` let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop = forall (i: nat { i < Seq.length v }) . {:pattern (Seq.index v i)} full td (Seq.index v i) let full_seq_seq_of_base_array (#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))] = assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i)) [@@noextract_to "krml"] // primitive val array_ref_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (n: array_len_t a) : stt unit (freeable_array (mk_array a n) ** array_pts_to (mk_array a n) s ** pure ( full_seq td s )) (fun _ -> emp) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) requires (freeable_array a ** array_pts_to a s ** pure ( full_seq td s )) ensures emp { let al = array_ptr_of a; let n: array_len_t al = array_len_of a; rewrite (freeable_array a) as (freeable_array (mk_array al n)); rewrite (array_pts_to a s) as (array_pts_to (mk_array al n) s); array_ref_free al n } ``` (* val has_array_of_ref (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : Tot vprop val has_array_of_ref_post (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : STGhost unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a) (True) (fun _ -> let (| al, len |) = a in array_ref_base_size al == 1sz /\ array_ref_offset al == 0sz /\ Ghost.reveal len == 1sz ) // val has_array_of_ref_inj // (#t: Type) // (#td: typedef t) // (r: ref td) // (a1 a2: array td) // : Lemma // (requires ( // has_array_of_ref r a1 /\ // has_array_of_ref r a2 // )) // (ensures a1 == a2) val ghost_array_of_ref_focus (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) (a: array td) : stt_ghost unit opened (pts_to r v ** has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** array_pts_to a (Seq.create 1 (Ghost.reveal v))) val ghost_array_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt_ghost (Ghost.erased (array td)) opened (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (a: array_ref td { array_ref_base_size a == 1sz /\ array_ref_offset a == 0sz }) (pts_to r v) (fun a -> array_pts_to (| a, Ghost.hide 1sz |) (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r (| a, Ghost.hide 1sz |)) inline_for_extraction [@@noextract_to "krml"] let array_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (array td) (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) = let al = array_ref_of_ref r in let a : array td = (| al, Ghost.hide 1sz |) in rewrite (array_pts_to _ _) (array_pts_to _ _); rewrite (has_array_of_ref _ _) (has_array_of_ref r a); return a val unarray_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (r: ref td) (a: array td) : stt_ghost (squash (Seq.length s == 1)) opened (array_pts_to a s ** has_array_of_ref r a) (fun _ -> pts_to r (Seq.index s 0) ** has_array_of_ref r a) *) val has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) : Tot vprop (* = SZ.v i < SZ.v (dsnd a) /\ has_base_array_cell (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r *) val has_array_cell_post (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r': ref td) : stt_ghost unit (has_array_cell a i r') (fun _ -> has_array_cell a i r' ** pure ( SZ.v i < SZ.v (dsnd a) )) val has_array_cell_has_base_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_array_cell a i r ** pure ( has_array_ref_base (array_ptr_of a) br )) (fun j -> has_base_array_cell br j r ** pure ( SZ.v j == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v i )) val has_base_array_cell_has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_base_array_cell br i r ** pure ( has_array_ref_base (array_ptr_of a) br /\ SZ.v i >= SZ.v (array_ref_offset (array_ptr_of a)) /\ SZ.v i < SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v (dsnd a) )) (fun j -> has_array_cell a j r ** pure ( SZ.v i == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v j )) val has_array_cell_inj (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit ( has_array_cell a i r1 ** has_array_cell a i r2 ) (fun _ -> has_array_cell a i r1 ** has_array_cell a i r2 ** ref_equiv r1 r2 ) // = has_base_array_cell_inj (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r1 r2 (* val has_array_cell_array_of_ref (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : SteelGhostT unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** has_array_cell a 0sz r) *) val ghost_array_cell_focus (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** has_array_cell a i r) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) val ghost_array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (r: Ghost.erased (ref td) { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) (fun r -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) [@@noextract_to "krml"] // primitive val array_ref_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (len: array_len_t a) (i: SZ.t) : stt (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v len }) (array_pts_to (mk_array a len) s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v len )) (fun r -> array_pts_to (mk_array a len) (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell (mk_array a len) i r) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) requires (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) returns r: (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) ensures (array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let r = array_ref_cell al len i; rewrite (array_pts_to (mk_array al len) (Seq.upd s (SZ.v i) (unknown td))) as (array_pts_to a (Seq.upd s (SZ.v i) (unknown td))); rewrite (has_array_cell (mk_array al len) i r) as (has_array_cell a i r); r } ``` val unarray_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (#v: Ghost.erased t) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pts_to r v ** has_array_cell a i r ** pure ( SZ.v i < Seq.length s ==> Seq.index s (SZ.v i) == unknown td )) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) v) ** has_array_cell a i r) val array_ref_shift (#t: Type) (#td: typedef t) (a: array_ref td) (i: SZ.t) : Ghost (array_ref td) (requires (SZ.v (array_ref_offset a) + SZ.v i <= SZ.v (array_ref_base_size a))) (ensures (fun y -> array_ref_base_size y == array_ref_base_size a /\ (forall ty r . has_array_ref_base a #ty r ==> has_array_ref_base y #ty (coerce_eq () r)) /\ array_ref_offset y == array_ref_offset a `SZ.add` i )) val array_ref_shift_zero (#t: Type) (#td: typedef t) (a: array_ref td) : Lemma (ensures ( array_ref_shift a 0sz == a )) val array_ref_shift_assoc (#t: Type) (#td: typedef t) (a: array_ref td) (i1 i2: SZ.t) : Lemma (requires (SZ.v (array_ref_offset a) + SZ.v i1 + SZ.v i2 <= SZ.v (array_ref_base_size a))) (ensures ( array_ref_shift a (SZ.add i1 i2) == array_ref_shift (array_ref_shift a i1) i2 )) inline_for_extraction [@@noextract_to "krml"] let array_split_l (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Pure (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, _ |) = a in (| al, Ghost.hide i |) let array_split_r (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Ghost (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, len |) = a in (| array_ref_shift al i, Ghost.hide (len `SZ.sub` i) |) val ghost_array_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (squash (SZ.v i <= SZ.v (dsnd a) /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pure ( SZ.v i <= SZ.v (dsnd a) \/ SZ.v i <= Seq.length s )) (fun _ -> array_pts_to (array_split_l a i) (Seq.slice s 0 (SZ.v i)) ** array_pts_to (array_split_r a i) (Seq.slice s (SZ.v i) (Seq.length s))) let array_ref_split_post (#t: Type) (#td: typedef t) (s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (sl sr: Ghost.erased (Seq.seq t)) : GTot prop = SZ.v i <= array_length a /\ Seq.length s == array_length a /\ Ghost.reveal sl == Seq.slice s 0 (SZ.v i) /\ Ghost.reveal sr == Seq.slice s (SZ.v i) (Seq.length s) [@@noextract_to "krml"] // primitive val array_ref_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (al: array_ref td) (len: array_len_t al) (i: SZ.t { SZ.v i <= SZ.v len }) : stt (array_ref td) (array_pts_to (mk_array al len) s) (fun ar -> exists* sl sr . array_pts_to (array_split_l (mk_array al len) i) sl ** array_pts_to (array_split_r (mk_array al len) i) sr ** pure ( array_ref_split_post s (mk_array al len) i sl sr /\ SZ.v i <= SZ.v len /\ SZ.v i <= Seq.length s /\ ar == array_ptr_of (array_split_r (mk_array al len) i) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t { SZ.v i <= array_length a }) requires (array_pts_to a s) returns a': array td ensures (exists* sl sr . array_pts_to (array_split_l a i) sl ** array_pts_to a' sr ** pure ( array_ref_split_post s a i sl sr /\ SZ.v i <= array_length a /\ SZ.v i <= Seq.length s /\ a' == array_split_r a i )) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let ar = array_ref_split al len i; with sl sr . assert ( array_pts_to (array_split_l (mk_array al len) i) sl ** array_pts_to (array_split_r (mk_array al len) i) sr ); let a' = mk_array ar (Ghost.hide (len `SZ.sub` i)); rewrite (array_pts_to (array_split_l (mk_array al len) i) sl) as (array_pts_to (array_split_l a i) sl); rewrite (array_pts_to (array_split_r (mk_array al len) i) sr) as (array_pts_to a' sr); a' } ``` val array_join (#t: Type) (#td: typedef t) (#sl #sr: Ghost.erased (Seq.seq t)) (a al ar: array td) (i: SZ.t) : stt_ghost unit (array_pts_to al sl ** array_pts_to ar sr ** pure ( SZ.v i <= SZ.v (dsnd a) /\ al == array_split_l a i /\ ar == array_split_r a i )) (fun _ -> array_pts_to a (sl `Seq.append` sr)) let fractionable_seq (#t: Type) (td: typedef t) (s: Seq.seq t) : GTot prop = forall (i: nat). i < Seq.length s ==> fractionable td (Seq.index s i) let mk_fraction_seq (#t: Type) (td: typedef t) (s: Seq.seq t) (p: perm) : Ghost (Seq.seq t) (requires (fractionable_seq td s)) (ensures (fun _ -> True)) = Seq.init_ghost (Seq.length s) (fun i -> mk_fraction td (Seq.index s i) p) let mk_fraction_seq_full (#t: Type0) (td: typedef t) (x: Seq.seq t) : Lemma (requires (fractionable_seq td x)) (ensures (mk_fraction_seq td x full_perm == x)) [SMTPat (mk_fraction_seq td x full_perm)] = assert (mk_fraction_seq td x full_perm `Seq.equal` x) val mk_fraction_seq_split_gen (#t: Type) (#td: typedef t) (r: array td) (v: Seq.seq t { fractionable_seq td v }) (p p1 p2: perm) : stt_ghost unit (array_pts_to r (mk_fraction_seq td v p) ** pure ( p == p1 `sum_perm` p2 /\ (p `lesser_equal_perm` full_perm \/ Seq.length v == 0) )) (fun _ -> array_pts_to r (mk_fraction_seq td v p1) ** array_pts_to r (mk_fraction_seq td v p2)) val mk_fraction_seq_split (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t) { fractionable_seq td v }) (p1 p2: perm) : stt_ghost unit (array_pts_to r v ** pure ( full_perm == p1 `sum_perm` p2 )) (fun _ -> array_pts_to r (mk_fraction_seq td v p1) ** array_pts_to r (mk_fraction_seq td v p2)) (* = mk_fraction_seq_full td v; rewrite (array_pts_to _ _) (array_pts_to _ _); mk_fraction_seq_split_gen r v full_perm p1 p2 *) val mk_fraction_seq_join (#t: Type) (#td: typedef t) (r: array td) (v: Seq.seq t { fractionable_seq td v }) (p1 p2: perm) : stt_ghost unit (array_pts_to r (mk_fraction_seq td v p1) ** array_pts_to r (mk_fraction_seq td v p2)) (fun _ -> array_pts_to r (mk_fraction_seq td v (p1 `sum_perm` p2))) val array_fractional_permissions_theorem (#t: Type) (#td: typedef t) (v1: Seq.seq t { fractionable_seq td v1 }) (v2: Seq.seq t { fractionable_seq td v2 }) (p1 p2: perm) (r: array td) : stt_ghost unit (array_pts_to r (mk_fraction_seq td v1 p1) ** array_pts_to r (mk_fraction_seq td v2 p2) ** pure ( full_seq td v1 /\ full_seq td v2 )) (fun _ -> array_pts_to r (mk_fraction_seq td v1 p1) ** array_pts_to r (mk_fraction_seq td v2 p2) ** pure ( v1 == v2 /\ (array_length r > 0 ==> (p1 `sum_perm` p2) `lesser_equal_perm` full_perm) ))
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
tn: Type0 -> td: Pulse.C.Types.Base.typedef t -> b: Pulse.C.Types.Array.base_array_t t tn n -> FStar.Pervasives.Lemma (ensures Pulse.C.Types.Array.fractionable_seq td (Pulse.C.Types.Array.seq_of_base_array b) <==> Pulse.C.Types.Base.fractionable (Pulse.C.Types.Array.base_array0 tn td n) b) [SMTPat (Pulse.C.Types.Array.fractionable_seq td (Pulse.C.Types.Array.seq_of_base_array b))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Pulse.C.Types.Base.typedef", "Pulse.C.Types.Array.array_size_t", "Pulse.C.Types.Array.base_array_t", "Prims._assert", "Prims.l_Forall", "Pulse.C.Types.Array.base_array_index_t", "Prims.eq2", "Pulse.C.Types.Array.base_array_index", "FStar.Seq.Base.index", "Pulse.C.Types.Array.seq_of_base_array", "FStar.SizeT.v", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "Pulse.C.Types.Array.fractionable_seq", "Pulse.C.Types.Base.fractionable", "Pulse.C.Types.Array.base_array0", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.prop", "Prims.Nil" ]
[]
false
false
true
false
false
let fractionable_seq_seq_of_base_array (#t tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (fractionable_seq td (seq_of_base_array b) <==> fractionable (base_array0 tn td n) b) ) [SMTPat (fractionable_seq td (seq_of_base_array b))] =
assert (forall (i: base_array_index_t n). base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i))
false
DM4F_layered.fst
DM4F_layered.return_wp
val return_wp (#a: Type) (#st: Type0) (x: a) : wp st a
val return_wp (#a: Type) (#st: Type0) (x: a) : wp st a
let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 46, "start_col": 0, "start_line": 45 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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 -> DM4F_layered.wp st a
Prims.Tot
[ "total" ]
[]
[ "DM4F_layered.wp" ]
[]
false
false
false
true
false
let return_wp (#a: Type) (#st: Type0) (x: a) : wp st a =
fun s0 p -> p x s0
false
DM4F_layered.fst
DM4F_layered.bind_wp
val bind_wp (#a #b: Type) (#st: Type0) (w1: wp st a) (w2: (a -> wp st b)) : wp st b
val bind_wp (#a #b: Type) (#st: Type0) (w1: wp st a) (w2: (a -> wp st b)) : wp st b
let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p)
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 43, "end_line": 54, "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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
w1: DM4F_layered.wp st a -> w2: (_: a -> DM4F_layered.wp st b) -> DM4F_layered.wp st b
Prims.Tot
[ "total" ]
[]
[ "DM4F_layered.wp", "DM4F_layered.post_t" ]
[]
false
false
false
true
false
let bind_wp (#a #b: Type) (#st: Type0) (w1: wp st a) (w2: (a -> wp st b)) : wp st b =
fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p)
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.mk_fraction_seq
val mk_fraction_seq (#t: Type) (td: typedef t) (s: Seq.seq t) (p: perm) : Ghost (Seq.seq t) (requires (fractionable_seq td s)) (ensures (fun _ -> True))
val mk_fraction_seq (#t: Type) (td: typedef t) (s: Seq.seq t) (p: perm) : Ghost (Seq.seq t) (requires (fractionable_seq td s)) (ensures (fun _ -> True))
let mk_fraction_seq (#t: Type) (td: typedef t) (s: Seq.seq t) (p: perm) : Ghost (Seq.seq t) (requires (fractionable_seq td s)) (ensures (fun _ -> True)) = Seq.init_ghost (Seq.length s) (fun i -> mk_fraction td (Seq.index s i) p)
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 75, "end_line": 985, "start_col": 0, "start_line": 982 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r let seq_of_base_array (#t: Type) (#tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) = Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i)) val ghost_array_of_base_focus (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost unit (pts_to r v ** pure ( has_array_of_base r a )) (fun _ -> array_pts_to a (seq_of_base_array v)) val ghost_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) : stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a }) (pts_to r v) (fun a -> array_pts_to a (seq_of_base_array v)) let array_ref_of_base_post (#t: Type) (#tn: Type0) (#n: Ghost.erased array_size_t) (#td: typedef t) (v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array_ref td) (ar: array td) : GTot prop = array_ptr_of ar == a /\ array_ref_base_size a == Ghost.reveal n /\ array_ref_offset a == 0sz /\ has_array_of_base r ar /\ Ghost.reveal (dsnd ar) == Ghost.reveal n // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) //: STAtomicBase (array_ref td) false opened Unobservable : stt (array_ref td) (pts_to r v) (fun a -> exists* (ar: array td) . array_pts_to ar (seq_of_base_array v) ** pure ( array_ref_of_base_post v r a ar )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) // : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable requires (pts_to r v) returns a: (a: array td { has_array_of_base r a }) ensures (array_pts_to a (seq_of_base_array v)) { let al = array_ref_of_base r; with ga . assert (array_pts_to #t #td ga (seq_of_base_array v)); let a = mk_array_or_null al (Ghost.hide (n <: SZ.t)); rewrite (array_pts_to ga (seq_of_base_array v)) as (array_pts_to a (seq_of_base_array v)); a } ``` val unarray_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost (Ghost.erased (base_array_t t tn n)) (array_pts_to a v ** pure ( has_array_of_base r a )) (fun v' -> pts_to r v' ** pure ( Ghost.reveal v `Seq.equal` seq_of_base_array v' )) val freeable_array (#t: Type) (#td: typedef t) (a: array td) : Tot vprop let freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop = if g_array_is_null a then emp else freeable_array a [@@noextract_to "krml"] // primitive val array_ptr_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) : stt (array_ptr td) emp (fun a -> exists* (ar: array_or_null td) (s: Seq.seq t) . freeable_or_null_array ar ** array_pts_to_or_null ar s ** pure ( array_ptr_of ar == a /\ (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s `Seq.equal` FStar.Seq.create (SZ.v sz) (uninitialized td) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) requires emp returns ar: array_or_null td ensures ( freeable_or_null_array ar ** ( exists* s . array_pts_to_or_null ar s ** pure ( (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s == FStar.Seq.create (SZ.v sz) (uninitialized td) ))) { let a : array_ptr td = array_ptr_alloc td sz; with ar' s . assert (freeable_or_null_array ar' ** array_pts_to_or_null #_ #td ar' s); let len: array_len_t a = array_len_of ar'; let ar = mk_array_or_null a len; rewrite (array_pts_to_or_null ar' s) as (array_pts_to_or_null ar s); rewrite (freeable_or_null_array ar') as (freeable_or_null_array ar); ar } ``` let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop = forall (i: nat { i < Seq.length v }) . {:pattern (Seq.index v i)} full td (Seq.index v i) let full_seq_seq_of_base_array (#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))] = assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i)) [@@noextract_to "krml"] // primitive val array_ref_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (n: array_len_t a) : stt unit (freeable_array (mk_array a n) ** array_pts_to (mk_array a n) s ** pure ( full_seq td s )) (fun _ -> emp) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) requires (freeable_array a ** array_pts_to a s ** pure ( full_seq td s )) ensures emp { let al = array_ptr_of a; let n: array_len_t al = array_len_of a; rewrite (freeable_array a) as (freeable_array (mk_array al n)); rewrite (array_pts_to a s) as (array_pts_to (mk_array al n) s); array_ref_free al n } ``` (* val has_array_of_ref (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : Tot vprop val has_array_of_ref_post (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : STGhost unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a) (True) (fun _ -> let (| al, len |) = a in array_ref_base_size al == 1sz /\ array_ref_offset al == 0sz /\ Ghost.reveal len == 1sz ) // val has_array_of_ref_inj // (#t: Type) // (#td: typedef t) // (r: ref td) // (a1 a2: array td) // : Lemma // (requires ( // has_array_of_ref r a1 /\ // has_array_of_ref r a2 // )) // (ensures a1 == a2) val ghost_array_of_ref_focus (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) (a: array td) : stt_ghost unit opened (pts_to r v ** has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** array_pts_to a (Seq.create 1 (Ghost.reveal v))) val ghost_array_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt_ghost (Ghost.erased (array td)) opened (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (a: array_ref td { array_ref_base_size a == 1sz /\ array_ref_offset a == 0sz }) (pts_to r v) (fun a -> array_pts_to (| a, Ghost.hide 1sz |) (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r (| a, Ghost.hide 1sz |)) inline_for_extraction [@@noextract_to "krml"] let array_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (array td) (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) = let al = array_ref_of_ref r in let a : array td = (| al, Ghost.hide 1sz |) in rewrite (array_pts_to _ _) (array_pts_to _ _); rewrite (has_array_of_ref _ _) (has_array_of_ref r a); return a val unarray_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (r: ref td) (a: array td) : stt_ghost (squash (Seq.length s == 1)) opened (array_pts_to a s ** has_array_of_ref r a) (fun _ -> pts_to r (Seq.index s 0) ** has_array_of_ref r a) *) val has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) : Tot vprop (* = SZ.v i < SZ.v (dsnd a) /\ has_base_array_cell (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r *) val has_array_cell_post (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r': ref td) : stt_ghost unit (has_array_cell a i r') (fun _ -> has_array_cell a i r' ** pure ( SZ.v i < SZ.v (dsnd a) )) val has_array_cell_has_base_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_array_cell a i r ** pure ( has_array_ref_base (array_ptr_of a) br )) (fun j -> has_base_array_cell br j r ** pure ( SZ.v j == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v i )) val has_base_array_cell_has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_base_array_cell br i r ** pure ( has_array_ref_base (array_ptr_of a) br /\ SZ.v i >= SZ.v (array_ref_offset (array_ptr_of a)) /\ SZ.v i < SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v (dsnd a) )) (fun j -> has_array_cell a j r ** pure ( SZ.v i == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v j )) val has_array_cell_inj (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit ( has_array_cell a i r1 ** has_array_cell a i r2 ) (fun _ -> has_array_cell a i r1 ** has_array_cell a i r2 ** ref_equiv r1 r2 ) // = has_base_array_cell_inj (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r1 r2 (* val has_array_cell_array_of_ref (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : SteelGhostT unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** has_array_cell a 0sz r) *) val ghost_array_cell_focus (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** has_array_cell a i r) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) val ghost_array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (r: Ghost.erased (ref td) { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) (fun r -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) [@@noextract_to "krml"] // primitive val array_ref_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (len: array_len_t a) (i: SZ.t) : stt (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v len }) (array_pts_to (mk_array a len) s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v len )) (fun r -> array_pts_to (mk_array a len) (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell (mk_array a len) i r) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) requires (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) returns r: (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) ensures (array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let r = array_ref_cell al len i; rewrite (array_pts_to (mk_array al len) (Seq.upd s (SZ.v i) (unknown td))) as (array_pts_to a (Seq.upd s (SZ.v i) (unknown td))); rewrite (has_array_cell (mk_array al len) i r) as (has_array_cell a i r); r } ``` val unarray_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (#v: Ghost.erased t) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pts_to r v ** has_array_cell a i r ** pure ( SZ.v i < Seq.length s ==> Seq.index s (SZ.v i) == unknown td )) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) v) ** has_array_cell a i r) val array_ref_shift (#t: Type) (#td: typedef t) (a: array_ref td) (i: SZ.t) : Ghost (array_ref td) (requires (SZ.v (array_ref_offset a) + SZ.v i <= SZ.v (array_ref_base_size a))) (ensures (fun y -> array_ref_base_size y == array_ref_base_size a /\ (forall ty r . has_array_ref_base a #ty r ==> has_array_ref_base y #ty (coerce_eq () r)) /\ array_ref_offset y == array_ref_offset a `SZ.add` i )) val array_ref_shift_zero (#t: Type) (#td: typedef t) (a: array_ref td) : Lemma (ensures ( array_ref_shift a 0sz == a )) val array_ref_shift_assoc (#t: Type) (#td: typedef t) (a: array_ref td) (i1 i2: SZ.t) : Lemma (requires (SZ.v (array_ref_offset a) + SZ.v i1 + SZ.v i2 <= SZ.v (array_ref_base_size a))) (ensures ( array_ref_shift a (SZ.add i1 i2) == array_ref_shift (array_ref_shift a i1) i2 )) inline_for_extraction [@@noextract_to "krml"] let array_split_l (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Pure (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, _ |) = a in (| al, Ghost.hide i |) let array_split_r (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Ghost (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, len |) = a in (| array_ref_shift al i, Ghost.hide (len `SZ.sub` i) |) val ghost_array_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (squash (SZ.v i <= SZ.v (dsnd a) /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pure ( SZ.v i <= SZ.v (dsnd a) \/ SZ.v i <= Seq.length s )) (fun _ -> array_pts_to (array_split_l a i) (Seq.slice s 0 (SZ.v i)) ** array_pts_to (array_split_r a i) (Seq.slice s (SZ.v i) (Seq.length s))) let array_ref_split_post (#t: Type) (#td: typedef t) (s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (sl sr: Ghost.erased (Seq.seq t)) : GTot prop = SZ.v i <= array_length a /\ Seq.length s == array_length a /\ Ghost.reveal sl == Seq.slice s 0 (SZ.v i) /\ Ghost.reveal sr == Seq.slice s (SZ.v i) (Seq.length s) [@@noextract_to "krml"] // primitive val array_ref_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (al: array_ref td) (len: array_len_t al) (i: SZ.t { SZ.v i <= SZ.v len }) : stt (array_ref td) (array_pts_to (mk_array al len) s) (fun ar -> exists* sl sr . array_pts_to (array_split_l (mk_array al len) i) sl ** array_pts_to (array_split_r (mk_array al len) i) sr ** pure ( array_ref_split_post s (mk_array al len) i sl sr /\ SZ.v i <= SZ.v len /\ SZ.v i <= Seq.length s /\ ar == array_ptr_of (array_split_r (mk_array al len) i) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t { SZ.v i <= array_length a }) requires (array_pts_to a s) returns a': array td ensures (exists* sl sr . array_pts_to (array_split_l a i) sl ** array_pts_to a' sr ** pure ( array_ref_split_post s a i sl sr /\ SZ.v i <= array_length a /\ SZ.v i <= Seq.length s /\ a' == array_split_r a i )) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let ar = array_ref_split al len i; with sl sr . assert ( array_pts_to (array_split_l (mk_array al len) i) sl ** array_pts_to (array_split_r (mk_array al len) i) sr ); let a' = mk_array ar (Ghost.hide (len `SZ.sub` i)); rewrite (array_pts_to (array_split_l (mk_array al len) i) sl) as (array_pts_to (array_split_l a i) sl); rewrite (array_pts_to (array_split_r (mk_array al len) i) sr) as (array_pts_to a' sr); a' } ``` val array_join (#t: Type) (#td: typedef t) (#sl #sr: Ghost.erased (Seq.seq t)) (a al ar: array td) (i: SZ.t) : stt_ghost unit (array_pts_to al sl ** array_pts_to ar sr ** pure ( SZ.v i <= SZ.v (dsnd a) /\ al == array_split_l a i /\ ar == array_split_r a i )) (fun _ -> array_pts_to a (sl `Seq.append` sr)) let fractionable_seq (#t: Type) (td: typedef t) (s: Seq.seq t) : GTot prop = forall (i: nat). i < Seq.length s ==> fractionable td (Seq.index s i)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
td: Pulse.C.Types.Base.typedef t -> s: FStar.Seq.Base.seq t -> p: PulseCore.FractionalPermission.perm -> Prims.Ghost (FStar.Seq.Base.seq t)
Prims.Ghost
[]
[]
[ "Pulse.C.Types.Base.typedef", "FStar.Seq.Base.seq", "PulseCore.FractionalPermission.perm", "FStar.Seq.Base.init_ghost", "FStar.Seq.Base.length", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Pulse.C.Types.Base.mk_fraction", "FStar.Seq.Base.index", "Pulse.C.Types.Array.fractionable_seq", "Prims.l_True" ]
[]
false
false
false
false
false
let mk_fraction_seq (#t: Type) (td: typedef t) (s: Seq.seq t) (p: perm) : Ghost (Seq.seq t) (requires (fractionable_seq td s)) (ensures (fun _ -> True)) =
Seq.init_ghost (Seq.length s) (fun i -> mk_fraction td (Seq.index s i) p)
false
DM4F_layered.fst
DM4F_layered.return
val return (a: Type) (x: a) (st: Type0) : repr a st (return_wp x)
val return (a: Type) (x: a) (st: Type0) : repr a st (return_wp x)
let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0)
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 49, "start_col": 0, "start_line": 48 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Type -> x: a -> st: Type0 -> DM4F_layered.repr a st (DM4F_layered.return_wp x)
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "DM4F_layered.repr", "DM4F_layered.return_wp" ]
[]
false
false
false
false
false
let return (a: Type) (x: a) (st: Type0) : repr a st (return_wp x) =
fun s0 -> (x, s0)
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.array_ref_split_post
val array_ref_split_post (#t: Type) (#td: typedef t) (s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (sl sr: Ghost.erased (Seq.seq t)) : GTot prop
val array_ref_split_post (#t: Type) (#td: typedef t) (s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (sl sr: Ghost.erased (Seq.seq t)) : GTot prop
let array_ref_split_post (#t: Type) (#td: typedef t) (s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (sl sr: Ghost.erased (Seq.seq t)) : GTot prop = SZ.v i <= array_length a /\ Seq.length s == array_length a /\ Ghost.reveal sl == Seq.slice s 0 (SZ.v i) /\ Ghost.reveal sr == Seq.slice s (SZ.v i) (Seq.length s)
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 56, "end_line": 906, "start_col": 0, "start_line": 896 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r let seq_of_base_array (#t: Type) (#tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) = Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i)) val ghost_array_of_base_focus (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost unit (pts_to r v ** pure ( has_array_of_base r a )) (fun _ -> array_pts_to a (seq_of_base_array v)) val ghost_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) : stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a }) (pts_to r v) (fun a -> array_pts_to a (seq_of_base_array v)) let array_ref_of_base_post (#t: Type) (#tn: Type0) (#n: Ghost.erased array_size_t) (#td: typedef t) (v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array_ref td) (ar: array td) : GTot prop = array_ptr_of ar == a /\ array_ref_base_size a == Ghost.reveal n /\ array_ref_offset a == 0sz /\ has_array_of_base r ar /\ Ghost.reveal (dsnd ar) == Ghost.reveal n // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) //: STAtomicBase (array_ref td) false opened Unobservable : stt (array_ref td) (pts_to r v) (fun a -> exists* (ar: array td) . array_pts_to ar (seq_of_base_array v) ** pure ( array_ref_of_base_post v r a ar )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) // : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable requires (pts_to r v) returns a: (a: array td { has_array_of_base r a }) ensures (array_pts_to a (seq_of_base_array v)) { let al = array_ref_of_base r; with ga . assert (array_pts_to #t #td ga (seq_of_base_array v)); let a = mk_array_or_null al (Ghost.hide (n <: SZ.t)); rewrite (array_pts_to ga (seq_of_base_array v)) as (array_pts_to a (seq_of_base_array v)); a } ``` val unarray_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost (Ghost.erased (base_array_t t tn n)) (array_pts_to a v ** pure ( has_array_of_base r a )) (fun v' -> pts_to r v' ** pure ( Ghost.reveal v `Seq.equal` seq_of_base_array v' )) val freeable_array (#t: Type) (#td: typedef t) (a: array td) : Tot vprop let freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop = if g_array_is_null a then emp else freeable_array a [@@noextract_to "krml"] // primitive val array_ptr_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) : stt (array_ptr td) emp (fun a -> exists* (ar: array_or_null td) (s: Seq.seq t) . freeable_or_null_array ar ** array_pts_to_or_null ar s ** pure ( array_ptr_of ar == a /\ (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s `Seq.equal` FStar.Seq.create (SZ.v sz) (uninitialized td) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) requires emp returns ar: array_or_null td ensures ( freeable_or_null_array ar ** ( exists* s . array_pts_to_or_null ar s ** pure ( (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s == FStar.Seq.create (SZ.v sz) (uninitialized td) ))) { let a : array_ptr td = array_ptr_alloc td sz; with ar' s . assert (freeable_or_null_array ar' ** array_pts_to_or_null #_ #td ar' s); let len: array_len_t a = array_len_of ar'; let ar = mk_array_or_null a len; rewrite (array_pts_to_or_null ar' s) as (array_pts_to_or_null ar s); rewrite (freeable_or_null_array ar') as (freeable_or_null_array ar); ar } ``` let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop = forall (i: nat { i < Seq.length v }) . {:pattern (Seq.index v i)} full td (Seq.index v i) let full_seq_seq_of_base_array (#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))] = assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i)) [@@noextract_to "krml"] // primitive val array_ref_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (n: array_len_t a) : stt unit (freeable_array (mk_array a n) ** array_pts_to (mk_array a n) s ** pure ( full_seq td s )) (fun _ -> emp) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) requires (freeable_array a ** array_pts_to a s ** pure ( full_seq td s )) ensures emp { let al = array_ptr_of a; let n: array_len_t al = array_len_of a; rewrite (freeable_array a) as (freeable_array (mk_array al n)); rewrite (array_pts_to a s) as (array_pts_to (mk_array al n) s); array_ref_free al n } ``` (* val has_array_of_ref (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : Tot vprop val has_array_of_ref_post (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : STGhost unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a) (True) (fun _ -> let (| al, len |) = a in array_ref_base_size al == 1sz /\ array_ref_offset al == 0sz /\ Ghost.reveal len == 1sz ) // val has_array_of_ref_inj // (#t: Type) // (#td: typedef t) // (r: ref td) // (a1 a2: array td) // : Lemma // (requires ( // has_array_of_ref r a1 /\ // has_array_of_ref r a2 // )) // (ensures a1 == a2) val ghost_array_of_ref_focus (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) (a: array td) : stt_ghost unit opened (pts_to r v ** has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** array_pts_to a (Seq.create 1 (Ghost.reveal v))) val ghost_array_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt_ghost (Ghost.erased (array td)) opened (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (a: array_ref td { array_ref_base_size a == 1sz /\ array_ref_offset a == 0sz }) (pts_to r v) (fun a -> array_pts_to (| a, Ghost.hide 1sz |) (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r (| a, Ghost.hide 1sz |)) inline_for_extraction [@@noextract_to "krml"] let array_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (array td) (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) = let al = array_ref_of_ref r in let a : array td = (| al, Ghost.hide 1sz |) in rewrite (array_pts_to _ _) (array_pts_to _ _); rewrite (has_array_of_ref _ _) (has_array_of_ref r a); return a val unarray_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (r: ref td) (a: array td) : stt_ghost (squash (Seq.length s == 1)) opened (array_pts_to a s ** has_array_of_ref r a) (fun _ -> pts_to r (Seq.index s 0) ** has_array_of_ref r a) *) val has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) : Tot vprop (* = SZ.v i < SZ.v (dsnd a) /\ has_base_array_cell (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r *) val has_array_cell_post (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r': ref td) : stt_ghost unit (has_array_cell a i r') (fun _ -> has_array_cell a i r' ** pure ( SZ.v i < SZ.v (dsnd a) )) val has_array_cell_has_base_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_array_cell a i r ** pure ( has_array_ref_base (array_ptr_of a) br )) (fun j -> has_base_array_cell br j r ** pure ( SZ.v j == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v i )) val has_base_array_cell_has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_base_array_cell br i r ** pure ( has_array_ref_base (array_ptr_of a) br /\ SZ.v i >= SZ.v (array_ref_offset (array_ptr_of a)) /\ SZ.v i < SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v (dsnd a) )) (fun j -> has_array_cell a j r ** pure ( SZ.v i == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v j )) val has_array_cell_inj (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit ( has_array_cell a i r1 ** has_array_cell a i r2 ) (fun _ -> has_array_cell a i r1 ** has_array_cell a i r2 ** ref_equiv r1 r2 ) // = has_base_array_cell_inj (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r1 r2 (* val has_array_cell_array_of_ref (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : SteelGhostT unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** has_array_cell a 0sz r) *) val ghost_array_cell_focus (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** has_array_cell a i r) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) val ghost_array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (r: Ghost.erased (ref td) { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) (fun r -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) [@@noextract_to "krml"] // primitive val array_ref_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (len: array_len_t a) (i: SZ.t) : stt (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v len }) (array_pts_to (mk_array a len) s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v len )) (fun r -> array_pts_to (mk_array a len) (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell (mk_array a len) i r) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) requires (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) returns r: (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) ensures (array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let r = array_ref_cell al len i; rewrite (array_pts_to (mk_array al len) (Seq.upd s (SZ.v i) (unknown td))) as (array_pts_to a (Seq.upd s (SZ.v i) (unknown td))); rewrite (has_array_cell (mk_array al len) i r) as (has_array_cell a i r); r } ``` val unarray_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (#v: Ghost.erased t) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pts_to r v ** has_array_cell a i r ** pure ( SZ.v i < Seq.length s ==> Seq.index s (SZ.v i) == unknown td )) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) v) ** has_array_cell a i r) val array_ref_shift (#t: Type) (#td: typedef t) (a: array_ref td) (i: SZ.t) : Ghost (array_ref td) (requires (SZ.v (array_ref_offset a) + SZ.v i <= SZ.v (array_ref_base_size a))) (ensures (fun y -> array_ref_base_size y == array_ref_base_size a /\ (forall ty r . has_array_ref_base a #ty r ==> has_array_ref_base y #ty (coerce_eq () r)) /\ array_ref_offset y == array_ref_offset a `SZ.add` i )) val array_ref_shift_zero (#t: Type) (#td: typedef t) (a: array_ref td) : Lemma (ensures ( array_ref_shift a 0sz == a )) val array_ref_shift_assoc (#t: Type) (#td: typedef t) (a: array_ref td) (i1 i2: SZ.t) : Lemma (requires (SZ.v (array_ref_offset a) + SZ.v i1 + SZ.v i2 <= SZ.v (array_ref_base_size a))) (ensures ( array_ref_shift a (SZ.add i1 i2) == array_ref_shift (array_ref_shift a i1) i2 )) inline_for_extraction [@@noextract_to "krml"] let array_split_l (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Pure (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, _ |) = a in (| al, Ghost.hide i |) let array_split_r (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Ghost (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, len |) = a in (| array_ref_shift al i, Ghost.hide (len `SZ.sub` i) |) val ghost_array_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (squash (SZ.v i <= SZ.v (dsnd a) /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pure ( SZ.v i <= SZ.v (dsnd a) \/ SZ.v i <= Seq.length s )) (fun _ -> array_pts_to (array_split_l a i) (Seq.slice s 0 (SZ.v i)) ** array_pts_to (array_split_r a i) (Seq.slice s (SZ.v i) (Seq.length s)))
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq t) -> a: Pulse.C.Types.Array.array td -> i: FStar.SizeT.t -> sl: FStar.Ghost.erased (FStar.Seq.Base.seq t) -> sr: FStar.Ghost.erased (FStar.Seq.Base.seq t) -> Prims.GTot Prims.prop
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.C.Types.Base.typedef", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Pulse.C.Types.Array.array", "FStar.SizeT.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.SizeT.v", "Pulse.C.Types.Array.array_length", "Prims.eq2", "Prims.nat", "FStar.Seq.Base.length", "FStar.Ghost.reveal", "FStar.Seq.Base.slice", "Prims.prop" ]
[]
false
false
false
false
true
let array_ref_split_post (#t: Type) (#td: typedef t) (s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (sl sr: Ghost.erased (Seq.seq t)) : GTot prop =
SZ.v i <= array_length a /\ Seq.length s == array_length a /\ Ghost.reveal sl == Seq.slice s 0 (SZ.v i) /\ Ghost.reveal sr == Seq.slice s (SZ.v i) (Seq.length s)
false
DM4F_layered.fst
DM4F_layered.wp_squash_lem
val wp_squash_lem (#a #st: _) (w: wp st a) (p: post_t st a) (s0: st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y)))
val wp_squash_lem (#a #st: _) (w: wp st a) (p: post_t st a) (s0: st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y)))
let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); }
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 72, "start_col": 0, "start_line": 64 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
w: DM4F_layered.wp st a -> p: DM4F_layered.post_t st a -> s0: st -> FStar.Pervasives.Lemma (requires w s0 p) (ensures w s0 (fun x y -> Prims.squash (p x y)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "DM4F_layered.wp", "DM4F_layered.post_t", "FStar.Calc.calc_finish", "Prims.logical", "Prims.l_imp", "Prims.squash", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Calc.calc_push_impl", "DM4F_layered.elim_mon", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let wp_squash_lem #a #st (w: wp st a) (p: post_t st a) (s0: st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) =
calc ( ==> ) { w s0 p; ( ==> ) { () } w s0 (fun x y -> p x y); ( ==> ) { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } w s0 (fun x y -> squash (p x y)); }
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.array_blit_post
val array_blit_post (#t: _) (#td: typedef t) (s0 s1: Ghost.erased (Seq.seq t)) (src: array td) (idx_src: SZ.t) (dst: array td) (idx_dst len: SZ.t) (s1': Ghost.erased (Seq.seq t)) : GTot prop
val array_blit_post (#t: _) (#td: typedef t) (s0 s1: Ghost.erased (Seq.seq t)) (src: array td) (idx_src: SZ.t) (dst: array td) (idx_dst len: SZ.t) (s1': Ghost.erased (Seq.seq t)) : GTot prop
let array_blit_post (#t:_) (#td: typedef t) (s0 s1:Ghost.erased (Seq.seq t)) (src:array td) (idx_src: SZ.t) (dst:array td) (idx_dst: SZ.t) (len: SZ.t) (s1' : Ghost.erased (Seq.seq t)) : GTot prop = SZ.v idx_src + SZ.v len <= array_length src /\ SZ.v idx_dst + SZ.v len <= array_length dst /\ array_length src == Seq.length s0 /\ array_length dst == Seq.length s1 /\ Seq.length s1' == Seq.length s1 /\ Seq.slice s1' (SZ.v idx_dst) (SZ.v idx_dst + SZ.v len) `Seq.equal` Seq.slice s0 (SZ.v idx_src) (SZ.v idx_src + SZ.v len) /\ Seq.slice s1' 0 (SZ.v idx_dst) `Seq.equal` Seq.slice s1 0 (SZ.v idx_dst) /\ Seq.slice s1' (SZ.v idx_dst + SZ.v len) (array_length dst) `Seq.equal` Seq.slice s1 (SZ.v idx_dst + SZ.v len) (array_length dst)
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 1063, "start_col": 0, "start_line": 1043 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r let seq_of_base_array (#t: Type) (#tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) = Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i)) val ghost_array_of_base_focus (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost unit (pts_to r v ** pure ( has_array_of_base r a )) (fun _ -> array_pts_to a (seq_of_base_array v)) val ghost_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) : stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a }) (pts_to r v) (fun a -> array_pts_to a (seq_of_base_array v)) let array_ref_of_base_post (#t: Type) (#tn: Type0) (#n: Ghost.erased array_size_t) (#td: typedef t) (v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array_ref td) (ar: array td) : GTot prop = array_ptr_of ar == a /\ array_ref_base_size a == Ghost.reveal n /\ array_ref_offset a == 0sz /\ has_array_of_base r ar /\ Ghost.reveal (dsnd ar) == Ghost.reveal n // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) //: STAtomicBase (array_ref td) false opened Unobservable : stt (array_ref td) (pts_to r v) (fun a -> exists* (ar: array td) . array_pts_to ar (seq_of_base_array v) ** pure ( array_ref_of_base_post v r a ar )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) // : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable requires (pts_to r v) returns a: (a: array td { has_array_of_base r a }) ensures (array_pts_to a (seq_of_base_array v)) { let al = array_ref_of_base r; with ga . assert (array_pts_to #t #td ga (seq_of_base_array v)); let a = mk_array_or_null al (Ghost.hide (n <: SZ.t)); rewrite (array_pts_to ga (seq_of_base_array v)) as (array_pts_to a (seq_of_base_array v)); a } ``` val unarray_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost (Ghost.erased (base_array_t t tn n)) (array_pts_to a v ** pure ( has_array_of_base r a )) (fun v' -> pts_to r v' ** pure ( Ghost.reveal v `Seq.equal` seq_of_base_array v' )) val freeable_array (#t: Type) (#td: typedef t) (a: array td) : Tot vprop let freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop = if g_array_is_null a then emp else freeable_array a [@@noextract_to "krml"] // primitive val array_ptr_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) : stt (array_ptr td) emp (fun a -> exists* (ar: array_or_null td) (s: Seq.seq t) . freeable_or_null_array ar ** array_pts_to_or_null ar s ** pure ( array_ptr_of ar == a /\ (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s `Seq.equal` FStar.Seq.create (SZ.v sz) (uninitialized td) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) requires emp returns ar: array_or_null td ensures ( freeable_or_null_array ar ** ( exists* s . array_pts_to_or_null ar s ** pure ( (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s == FStar.Seq.create (SZ.v sz) (uninitialized td) ))) { let a : array_ptr td = array_ptr_alloc td sz; with ar' s . assert (freeable_or_null_array ar' ** array_pts_to_or_null #_ #td ar' s); let len: array_len_t a = array_len_of ar'; let ar = mk_array_or_null a len; rewrite (array_pts_to_or_null ar' s) as (array_pts_to_or_null ar s); rewrite (freeable_or_null_array ar') as (freeable_or_null_array ar); ar } ``` let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop = forall (i: nat { i < Seq.length v }) . {:pattern (Seq.index v i)} full td (Seq.index v i) let full_seq_seq_of_base_array (#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))] = assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i)) [@@noextract_to "krml"] // primitive val array_ref_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (n: array_len_t a) : stt unit (freeable_array (mk_array a n) ** array_pts_to (mk_array a n) s ** pure ( full_seq td s )) (fun _ -> emp) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) requires (freeable_array a ** array_pts_to a s ** pure ( full_seq td s )) ensures emp { let al = array_ptr_of a; let n: array_len_t al = array_len_of a; rewrite (freeable_array a) as (freeable_array (mk_array al n)); rewrite (array_pts_to a s) as (array_pts_to (mk_array al n) s); array_ref_free al n } ``` (* val has_array_of_ref (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : Tot vprop val has_array_of_ref_post (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : STGhost unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a) (True) (fun _ -> let (| al, len |) = a in array_ref_base_size al == 1sz /\ array_ref_offset al == 0sz /\ Ghost.reveal len == 1sz ) // val has_array_of_ref_inj // (#t: Type) // (#td: typedef t) // (r: ref td) // (a1 a2: array td) // : Lemma // (requires ( // has_array_of_ref r a1 /\ // has_array_of_ref r a2 // )) // (ensures a1 == a2) val ghost_array_of_ref_focus (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) (a: array td) : stt_ghost unit opened (pts_to r v ** has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** array_pts_to a (Seq.create 1 (Ghost.reveal v))) val ghost_array_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt_ghost (Ghost.erased (array td)) opened (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (a: array_ref td { array_ref_base_size a == 1sz /\ array_ref_offset a == 0sz }) (pts_to r v) (fun a -> array_pts_to (| a, Ghost.hide 1sz |) (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r (| a, Ghost.hide 1sz |)) inline_for_extraction [@@noextract_to "krml"] let array_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (array td) (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) = let al = array_ref_of_ref r in let a : array td = (| al, Ghost.hide 1sz |) in rewrite (array_pts_to _ _) (array_pts_to _ _); rewrite (has_array_of_ref _ _) (has_array_of_ref r a); return a val unarray_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (r: ref td) (a: array td) : stt_ghost (squash (Seq.length s == 1)) opened (array_pts_to a s ** has_array_of_ref r a) (fun _ -> pts_to r (Seq.index s 0) ** has_array_of_ref r a) *) val has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) : Tot vprop (* = SZ.v i < SZ.v (dsnd a) /\ has_base_array_cell (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r *) val has_array_cell_post (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r': ref td) : stt_ghost unit (has_array_cell a i r') (fun _ -> has_array_cell a i r' ** pure ( SZ.v i < SZ.v (dsnd a) )) val has_array_cell_has_base_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_array_cell a i r ** pure ( has_array_ref_base (array_ptr_of a) br )) (fun j -> has_base_array_cell br j r ** pure ( SZ.v j == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v i )) val has_base_array_cell_has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_base_array_cell br i r ** pure ( has_array_ref_base (array_ptr_of a) br /\ SZ.v i >= SZ.v (array_ref_offset (array_ptr_of a)) /\ SZ.v i < SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v (dsnd a) )) (fun j -> has_array_cell a j r ** pure ( SZ.v i == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v j )) val has_array_cell_inj (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit ( has_array_cell a i r1 ** has_array_cell a i r2 ) (fun _ -> has_array_cell a i r1 ** has_array_cell a i r2 ** ref_equiv r1 r2 ) // = has_base_array_cell_inj (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r1 r2 (* val has_array_cell_array_of_ref (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : SteelGhostT unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** has_array_cell a 0sz r) *) val ghost_array_cell_focus (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** has_array_cell a i r) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) val ghost_array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (r: Ghost.erased (ref td) { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) (fun r -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) [@@noextract_to "krml"] // primitive val array_ref_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (len: array_len_t a) (i: SZ.t) : stt (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v len }) (array_pts_to (mk_array a len) s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v len )) (fun r -> array_pts_to (mk_array a len) (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell (mk_array a len) i r) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) requires (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) returns r: (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) ensures (array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let r = array_ref_cell al len i; rewrite (array_pts_to (mk_array al len) (Seq.upd s (SZ.v i) (unknown td))) as (array_pts_to a (Seq.upd s (SZ.v i) (unknown td))); rewrite (has_array_cell (mk_array al len) i r) as (has_array_cell a i r); r } ``` val unarray_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (#v: Ghost.erased t) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pts_to r v ** has_array_cell a i r ** pure ( SZ.v i < Seq.length s ==> Seq.index s (SZ.v i) == unknown td )) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) v) ** has_array_cell a i r) val array_ref_shift (#t: Type) (#td: typedef t) (a: array_ref td) (i: SZ.t) : Ghost (array_ref td) (requires (SZ.v (array_ref_offset a) + SZ.v i <= SZ.v (array_ref_base_size a))) (ensures (fun y -> array_ref_base_size y == array_ref_base_size a /\ (forall ty r . has_array_ref_base a #ty r ==> has_array_ref_base y #ty (coerce_eq () r)) /\ array_ref_offset y == array_ref_offset a `SZ.add` i )) val array_ref_shift_zero (#t: Type) (#td: typedef t) (a: array_ref td) : Lemma (ensures ( array_ref_shift a 0sz == a )) val array_ref_shift_assoc (#t: Type) (#td: typedef t) (a: array_ref td) (i1 i2: SZ.t) : Lemma (requires (SZ.v (array_ref_offset a) + SZ.v i1 + SZ.v i2 <= SZ.v (array_ref_base_size a))) (ensures ( array_ref_shift a (SZ.add i1 i2) == array_ref_shift (array_ref_shift a i1) i2 )) inline_for_extraction [@@noextract_to "krml"] let array_split_l (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Pure (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, _ |) = a in (| al, Ghost.hide i |) let array_split_r (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Ghost (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, len |) = a in (| array_ref_shift al i, Ghost.hide (len `SZ.sub` i) |) val ghost_array_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (squash (SZ.v i <= SZ.v (dsnd a) /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pure ( SZ.v i <= SZ.v (dsnd a) \/ SZ.v i <= Seq.length s )) (fun _ -> array_pts_to (array_split_l a i) (Seq.slice s 0 (SZ.v i)) ** array_pts_to (array_split_r a i) (Seq.slice s (SZ.v i) (Seq.length s))) let array_ref_split_post (#t: Type) (#td: typedef t) (s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (sl sr: Ghost.erased (Seq.seq t)) : GTot prop = SZ.v i <= array_length a /\ Seq.length s == array_length a /\ Ghost.reveal sl == Seq.slice s 0 (SZ.v i) /\ Ghost.reveal sr == Seq.slice s (SZ.v i) (Seq.length s) [@@noextract_to "krml"] // primitive val array_ref_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (al: array_ref td) (len: array_len_t al) (i: SZ.t { SZ.v i <= SZ.v len }) : stt (array_ref td) (array_pts_to (mk_array al len) s) (fun ar -> exists* sl sr . array_pts_to (array_split_l (mk_array al len) i) sl ** array_pts_to (array_split_r (mk_array al len) i) sr ** pure ( array_ref_split_post s (mk_array al len) i sl sr /\ SZ.v i <= SZ.v len /\ SZ.v i <= Seq.length s /\ ar == array_ptr_of (array_split_r (mk_array al len) i) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t { SZ.v i <= array_length a }) requires (array_pts_to a s) returns a': array td ensures (exists* sl sr . array_pts_to (array_split_l a i) sl ** array_pts_to a' sr ** pure ( array_ref_split_post s a i sl sr /\ SZ.v i <= array_length a /\ SZ.v i <= Seq.length s /\ a' == array_split_r a i )) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let ar = array_ref_split al len i; with sl sr . assert ( array_pts_to (array_split_l (mk_array al len) i) sl ** array_pts_to (array_split_r (mk_array al len) i) sr ); let a' = mk_array ar (Ghost.hide (len `SZ.sub` i)); rewrite (array_pts_to (array_split_l (mk_array al len) i) sl) as (array_pts_to (array_split_l a i) sl); rewrite (array_pts_to (array_split_r (mk_array al len) i) sr) as (array_pts_to a' sr); a' } ``` val array_join (#t: Type) (#td: typedef t) (#sl #sr: Ghost.erased (Seq.seq t)) (a al ar: array td) (i: SZ.t) : stt_ghost unit (array_pts_to al sl ** array_pts_to ar sr ** pure ( SZ.v i <= SZ.v (dsnd a) /\ al == array_split_l a i /\ ar == array_split_r a i )) (fun _ -> array_pts_to a (sl `Seq.append` sr)) let fractionable_seq (#t: Type) (td: typedef t) (s: Seq.seq t) : GTot prop = forall (i: nat). i < Seq.length s ==> fractionable td (Seq.index s i) let mk_fraction_seq (#t: Type) (td: typedef t) (s: Seq.seq t) (p: perm) : Ghost (Seq.seq t) (requires (fractionable_seq td s)) (ensures (fun _ -> True)) = Seq.init_ghost (Seq.length s) (fun i -> mk_fraction td (Seq.index s i) p) let mk_fraction_seq_full (#t: Type0) (td: typedef t) (x: Seq.seq t) : Lemma (requires (fractionable_seq td x)) (ensures (mk_fraction_seq td x full_perm == x)) [SMTPat (mk_fraction_seq td x full_perm)] = assert (mk_fraction_seq td x full_perm `Seq.equal` x) val mk_fraction_seq_split_gen (#t: Type) (#td: typedef t) (r: array td) (v: Seq.seq t { fractionable_seq td v }) (p p1 p2: perm) : stt_ghost unit (array_pts_to r (mk_fraction_seq td v p) ** pure ( p == p1 `sum_perm` p2 /\ (p `lesser_equal_perm` full_perm \/ Seq.length v == 0) )) (fun _ -> array_pts_to r (mk_fraction_seq td v p1) ** array_pts_to r (mk_fraction_seq td v p2)) val mk_fraction_seq_split (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t) { fractionable_seq td v }) (p1 p2: perm) : stt_ghost unit (array_pts_to r v ** pure ( full_perm == p1 `sum_perm` p2 )) (fun _ -> array_pts_to r (mk_fraction_seq td v p1) ** array_pts_to r (mk_fraction_seq td v p2)) (* = mk_fraction_seq_full td v; rewrite (array_pts_to _ _) (array_pts_to _ _); mk_fraction_seq_split_gen r v full_perm p1 p2 *) val mk_fraction_seq_join (#t: Type) (#td: typedef t) (r: array td) (v: Seq.seq t { fractionable_seq td v }) (p1 p2: perm) : stt_ghost unit (array_pts_to r (mk_fraction_seq td v p1) ** array_pts_to r (mk_fraction_seq td v p2)) (fun _ -> array_pts_to r (mk_fraction_seq td v (p1 `sum_perm` p2))) val array_fractional_permissions_theorem (#t: Type) (#td: typedef t) (v1: Seq.seq t { fractionable_seq td v1 }) (v2: Seq.seq t { fractionable_seq td v2 }) (p1 p2: perm) (r: array td) : stt_ghost unit (array_pts_to r (mk_fraction_seq td v1 p1) ** array_pts_to r (mk_fraction_seq td v2 p2) ** pure ( full_seq td v1 /\ full_seq td v2 )) (fun _ -> array_pts_to r (mk_fraction_seq td v1 p1) ** array_pts_to r (mk_fraction_seq td v2 p2) ** pure ( v1 == v2 /\ (array_length r > 0 ==> (p1 `sum_perm` p2) `lesser_equal_perm` full_perm) )) let fractionable_seq_seq_of_base_array (#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (fractionable_seq td (seq_of_base_array b) <==> fractionable (base_array0 tn td n) b)) [SMTPat (fractionable_seq td (seq_of_base_array b))] = assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i))
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
s0: FStar.Ghost.erased (FStar.Seq.Base.seq t) -> s1: FStar.Ghost.erased (FStar.Seq.Base.seq t) -> src: Pulse.C.Types.Array.array td -> idx_src: FStar.SizeT.t -> dst: Pulse.C.Types.Array.array td -> idx_dst: FStar.SizeT.t -> len: FStar.SizeT.t -> s1': FStar.Ghost.erased (FStar.Seq.Base.seq t) -> Prims.GTot Prims.prop
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.C.Types.Base.typedef", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Pulse.C.Types.Array.array", "FStar.SizeT.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.SizeT.v", "Pulse.C.Types.Array.array_length", "Prims.eq2", "Prims.nat", "FStar.Seq.Base.length", "FStar.Ghost.reveal", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.prop" ]
[]
false
false
false
false
true
let array_blit_post (#t: _) (#td: typedef t) (s0 s1: Ghost.erased (Seq.seq t)) (src: array td) (idx_src: SZ.t) (dst: array td) (idx_dst len: SZ.t) (s1': Ghost.erased (Seq.seq t)) : GTot prop =
SZ.v idx_src + SZ.v len <= array_length src /\ SZ.v idx_dst + SZ.v len <= array_length dst /\ array_length src == Seq.length s0 /\ array_length dst == Seq.length s1 /\ Seq.length s1' == Seq.length s1 /\ (Seq.slice s1' (SZ.v idx_dst) (SZ.v idx_dst + SZ.v len)) `Seq.equal` (Seq.slice s0 (SZ.v idx_src) (SZ.v idx_src + SZ.v len)) /\ (Seq.slice s1' 0 (SZ.v idx_dst)) `Seq.equal` (Seq.slice s1 0 (SZ.v idx_dst)) /\ (Seq.slice s1' (SZ.v idx_dst + SZ.v len) (array_length dst)) `Seq.equal` (Seq.slice s1 (SZ.v idx_dst + SZ.v len) (array_length dst))
false
DM4F_layered.fst
DM4F_layered.lift_id_st_wp
val lift_id_st_wp (#a #st: _) (w: pure_wp a) : wp st a
val lift_id_st_wp (#a #st: _) (w: pure_wp a) : wp st a
let lift_id_st_wp #a #st (w : pure_wp a) : wp st a = elim_pure_wp_monotonicity_forall (); fun s0 p -> w (fun x -> p x s0)
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 132, "start_col": 0, "start_line": 130 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); } let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1 let ite_wp #a #st (b:bool) (w1 w2 : wp st a) : wp st a = fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p) let if_then_else (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) (g : repr a st wpg) (b : bool) : Type = repr a st (ite_wp b wpf wpg) let stronger (#a:Type) (#st:Type0) (w1 w2 : wp st a) : Type0 = forall s0 p. w1 s0 p ==> w2 s0 p let subcomp (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True)) = f total reifiable reflectable effect { ST (a:Type) ([@@@ effect_param] st:Type0) (_:wp st a) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_st_wp #a #st (w : pure_wp a) : wp st a = FStar.Monotonic.Pure.elim_pure_wp_monotonicity w; let r = fun s0 p -> w (fun x -> p x s0) in r
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
w: Prims.pure_wp a -> DM4F_layered.wp st a
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.l_True", "Prims.pure_pre", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall", "DM4F_layered.wp" ]
[]
false
false
false
true
false
let lift_id_st_wp #a #st (w: pure_wp a) : wp st a =
elim_pure_wp_monotonicity_forall (); fun s0 p -> w (fun x -> p x s0)
false
DM4F_layered.fst
DM4F_layered.bind
val bind (a b: Type) (st: Type0) (wp_c: wp st a) (wp_f: (a -> wp st b)) (c: repr a st wp_c) (f: (x: a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f)
val bind (a b: Type) (st: Type0) (wp_c: wp st a) (wp_f: (a -> wp st b)) (c: repr a st wp_c) (f: (x: a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f)
let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 86, "start_col": 0, "start_line": 74 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Type -> b: Type -> st: Type0 -> wp_c: DM4F_layered.wp st a -> wp_f: (_: a -> DM4F_layered.wp st b) -> c: DM4F_layered.repr a st wp_c -> f: (x: a -> DM4F_layered.repr b st (wp_f x)) -> DM4F_layered.repr b st (DM4F_layered.bind_wp wp_c wp_f)
Prims.Tot
[ "total" ]
[]
[ "DM4F_layered.wp", "DM4F_layered.repr", "FStar.Pervasives.Native.tuple2", "DM4F_layered.bind_wp", "Prims.unit", "FStar.Stubs.Tactics.V2.Builtins.dump", "FStar.Tactics.V2.Derived.apply_lemma", "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.V2.SyntaxCoercions.binding_to_term", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.nth_var", "FStar.Tactics.V2.Logic.explode" ]
[]
false
false
false
false
false
let bind (a b: Type) (st: Type0) (wp_c: wp st a) (wp_f: (a -> wp st b)) (c: repr a st wp_c) (f: (x: a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") =
fun s0 -> let y, s1 = c s0 in f y s1
false
DM4F_layered.fst
DM4F_layered.subcomp
val subcomp (a: Type) (st: Type0) (wpf wpg: wp st a) (f: repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True))
val subcomp (a: Type) (st: Type0) (wpf wpg: wp st a) (f: repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True))
let subcomp (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True)) = f
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 115, "start_col": 0, "start_line": 107 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); } let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1 let ite_wp #a #st (b:bool) (w1 w2 : wp st a) : wp st a = fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p) let if_then_else (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) (g : repr a st wpg) (b : bool) : Type = repr a st (ite_wp b wpf wpg) let stronger (#a:Type) (#st:Type0) (w1 w2 : wp st a) : Type0 = forall s0 p. w1 s0 p ==> w2 s0 p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Type -> st: Type0 -> wpf: DM4F_layered.wp st a -> wpg: DM4F_layered.wp st a -> f: DM4F_layered.repr a st wpf -> Prims.Pure (DM4F_layered.repr a st wpg)
Prims.Pure
[]
[]
[ "DM4F_layered.wp", "DM4F_layered.repr", "DM4F_layered.stronger", "Prims.l_True" ]
[]
false
false
false
false
false
let subcomp (a: Type) (st: Type0) (wpf wpg: wp st a) (f: repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True)) =
f
false
Pulse.C.Types.Array.fsti
Pulse.C.Types.Array.mk_fraction_seq_full
val mk_fraction_seq_full (#t: Type0) (td: typedef t) (x: Seq.seq t) : Lemma (requires (fractionable_seq td x)) (ensures (mk_fraction_seq td x full_perm == x)) [SMTPat (mk_fraction_seq td x full_perm)]
val mk_fraction_seq_full (#t: Type0) (td: typedef t) (x: Seq.seq t) : Lemma (requires (fractionable_seq td x)) (ensures (mk_fraction_seq td x full_perm == x)) [SMTPat (mk_fraction_seq td x full_perm)]
let mk_fraction_seq_full (#t: Type0) (td: typedef t) (x: Seq.seq t) : Lemma (requires (fractionable_seq td x)) (ensures (mk_fraction_seq td x full_perm == x)) [SMTPat (mk_fraction_seq td x full_perm)] = assert (mk_fraction_seq td x full_perm `Seq.equal` x)
{ "file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Array.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 991, "start_col": 0, "start_line": 987 }
module Pulse.C.Types.Array open Pulse.Lib.Pervasives include Pulse.C.Types.Base open Pulse.C.Typenat module SZ = FStar.SizeT // To be extracted as: t[tn] // Per the C standard, base array types must be of nonzero size inline_for_extraction [@@noextract_to "krml"] let array_size_t = (n: SZ.t { SZ.v n > 0 }) val base_array_t ([@@@strictly_positive] t: Type0) (tn: Type0 (* using Typenat (or Typestring for `#define`d constants) *)) (n: array_size_t) : Type0 inline_for_extraction [@@noextract_to "krml"] let base_array_index_t (n: array_size_t) : Tot eqtype = Pulse.C.Types.Array.Base.array_domain (Ghost.hide n) [@@noextract_to "krml"] val base_array0 (#t: Type0) (tn: Type0) (td: typedef t) (n: array_size_t) : Tot (typedef (base_array_t t tn n)) inline_for_extraction [@@noextract_to "krml"] // proof-only let base_array (#t: Type0) (#tn: Type0) (td: typedef t) (n: nat {SZ.fits n /\ n > 0}) (# [solve_nat_t_of_nat ()] prf: squash (norm norm_typenat (nat_t_of_nat n == tn))) : Tot (typedef (base_array_t t tn (SZ.uint_to_t n))) = base_array0 tn td (SZ.uint_to_t n) val base_array_index (#t: Type0) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (i: base_array_index_t n) : GTot t val base_array_eq (#t: Type0) (#tn: Type0) (#n: array_size_t) (a1 a2: base_array_t t tn n) : Ghost prop (requires True) (ensures (fun y -> (y <==> (a1 == a2)) /\ (y <==> (forall (i: base_array_index_t n) . base_array_index a1 i == base_array_index a2 i)) )) val mk_base_array (#t: Type) (tn: Type0) (n: array_size_t) (v: Seq.seq t) : Ghost (base_array_t t tn n) (requires ( Seq.length v == SZ.v n )) (ensures (fun y -> True)) val mk_base_array_index (#t: Type) (tn: Type) (n: array_size_t) (v: Seq.seq t) (i: base_array_index_t n) : Lemma (requires (Seq.length v == SZ.v n)) (ensures ( Seq.length v == SZ.v n /\ base_array_index (mk_base_array tn n v) i == Seq.index v (SZ.v i) )) [SMTPat (base_array_index (mk_base_array tn n v) i)] let mk_base_array_inj (#t: Type) (tn: Type0) (n: array_size_t) (v1 v2: Seq.seq t) : Lemma (requires ( Seq.length v1 == SZ.v n /\ Seq.length v2 == SZ.v n /\ mk_base_array tn n v1 == mk_base_array tn n v2 )) (ensures (v1 == v2)) [SMTPat (mk_base_array tn n v1); SMTPat (mk_base_array tn n v2)] = assert (forall (i: nat) . i < SZ.v n ==> base_array_index (mk_base_array tn n v1) (SZ.uint_to_t i) == base_array_index (mk_base_array tn n v2) (SZ.uint_to_t i)); assert (v1 `Seq.equal` v2) val base_array_fractionable (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) : Lemma ( fractionable (base_array0 tn td n) a <==> (forall (i: base_array_index_t n) . fractionable td (base_array_index a i)) ) [SMTPat (fractionable (base_array0 tn td n) a)] val base_array_mk_fraction (#t: Type) (#tn: Type0) (#n: array_size_t) (a: base_array_t t tn n) (td: typedef t) (p: perm) (i: base_array_index_t n) : Lemma (requires ( fractionable (base_array0 tn td n) a )) (ensures ( fractionable (base_array0 tn td n) a /\ base_array_index (mk_fraction (base_array0 tn td n) a p) i == mk_fraction td (base_array_index a i) p )) [SMTPat (base_array_index (mk_fraction (base_array0 tn td n) a p) i)] val base_array_index_unknown (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (unknown (base_array0 tn td n)) i == unknown td) [SMTPat (base_array_index (unknown (base_array0 tn td n)) i)] val base_array_index_uninitialized (#t: Type) (tn: Type0) (n: array_size_t) (td: typedef t) (i: base_array_index_t n) : Lemma (base_array_index (uninitialized (base_array0 tn td n)) i == uninitialized td) [SMTPat (base_array_index (uninitialized (base_array0 tn td n)) i)] val base_array_index_full (#t: Type) (#tn: Type0) (#n: array_size_t) (td: typedef t) (x: base_array_t t tn n) : Lemma (full (base_array0 tn td n) x <==> (forall (i: base_array_index_t n) . full td (base_array_index x i))) [SMTPat (full (base_array0 tn td n) x)] val has_base_array_cell (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : Tot vprop val has_base_array_cell_post (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** pure ( SZ.v i < SZ.v n )) val has_base_array_cell_dup (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r i r') (fun _ -> has_base_array_cell r i r' ** has_base_array_cell r i r') val has_base_array_cell_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** has_base_array_cell r i r2) (fun _ -> has_base_array_cell r i r1 ** has_base_array_cell r i r2 ** ref_equiv r1 r2) val has_base_array_cell_equiv_from (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r1 r2: ref (base_array0 tn td n)) (i: SZ.t) (r': ref td) : stt_ghost unit (has_base_array_cell r1 i r' ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r2 i r' ** ref_equiv r1 r2) val has_base_array_cell_equiv_to (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit (has_base_array_cell r i r1 ** ref_equiv r1 r2) (fun _ -> has_base_array_cell r i r2 ** ref_equiv r1 r2) // contrary to array fields, one is not supposed to take an array cell directly from a base array. one should use arrays instead // To be extracted to: t* (array type decays to pointer type) // We still want to prove that cutting off some cell range on the // right-hand end of an array won't change the C pointer to which an // array extracts to. This is why we separately introduce `array_ref` // to represent the "base+offset" pointer, and `array` which holds the // ghost length of an array. [@@noextract_to "krml"] // primitive val array_void_ptr : Type0 [@@noextract_to "krml"] // primitive let array_ptr_gen ([@@@unused] t: Type0) : Tot Type0 = array_void_ptr inline_for_extraction [@@noextract_to "krml"] // primitive let array_ptr (#t: Type) (td: typedef t) = array_ptr_gen t [@@noextract_to "krml"] // primitive val null_array_void_ptr: array_void_ptr [@@noextract_to "krml"] // primitive let null_array_ptr (#t: Type) (td: typedef t) : Tot (array_ptr td) = null_array_void_ptr val g_array_ptr_is_null (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost bool (requires True) (ensures (fun y -> y == true <==> a == null_array_ptr td)) inline_for_extraction [@@noextract_to "krml"] let array_ref (#t: Type) (td: typedef t) = (a: array_ptr td { g_array_ptr_is_null a == false }) (* val array_ref_base_size_type (#t: Type) (#td: typedef t) (a: array_ref td) : GTot Type0 *) val array_ref_base_size (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y == 0 <==> a == null_array_ptr td)) val has_array_ref_base (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r: ref (base_array0 ty td (array_ref_base_size a))) : GTot prop val has_array_ref_base_inj (#t: Type) (#td: typedef t) (a: array_ref td) (#ty: Type) (r1 r2: ref (base_array0 ty td (array_ref_base_size a))) : Lemma (requires (has_array_ref_base a r1 /\ has_array_ref_base a r2)) (ensures (r1 == r2)) val array_ref_offset (#t: Type) (#td: typedef t) (a: array_ptr td) : Ghost SZ.t (requires True) (ensures (fun y -> SZ.v y <= SZ.v (array_ref_base_size a))) val array_ref_base_offset_inj (#t: Type) (#td: typedef t) (#ty: Type) (a1: array_ref td) (r1: ref (base_array0 ty td (array_ref_base_size a1))) (a2: array_ref td) (r2: ref (base_array0 ty td (array_ref_base_size a2))) : Lemma (requires ( array_ref_base_size a1 == array_ref_base_size a2 /\ has_array_ref_base a1 r1 /\ has_array_ref_base a2 r2 /\ r1 == coerce_eq () r2 /\ array_ref_offset a1 == array_ref_offset a2 )) (ensures (a1 == a2)) inline_for_extraction [@@noextract_to "krml"] let array_len_t (#t: Type) (#td: typedef t) (r: array_ptr td) : Tot Type0 = (len: Ghost.erased SZ.t { SZ.v (array_ref_offset r) + SZ.v len <= SZ.v (array_ref_base_size r) }) inline_for_extraction [@@noextract_to "krml"] let array_or_null (#t: Type) (td: typedef t) : Tot Type0 = (r: array_ptr td & array_len_t r) inline_for_extraction [@@noextract_to "krml"] let array_ptr_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_ptr td) = match ar with | (| a, _ |) -> a let array_len_of (#t: Type) (#td: typedef t) (ar: array_or_null td) : Tot (array_len_t (array_ptr_of ar)) = match ar with | (| _, a |) -> a inline_for_extraction [@@noextract_to "krml"] let mk_array_or_null (#t: Type) (#td: typedef t) (a: array_ptr td) (len: array_len_t a) : Tot (array_or_null td) = (| a, len |) let g_array_is_null (#t: Type) (#td: typedef t) (a: array_or_null td) : GTot bool = g_array_ptr_is_null (array_ptr_of a) inline_for_extraction [@@noextract_to "krml"] let array (#t: Type) (td: typedef t) : Tot Type0 = (a: array_or_null td { g_array_is_null a == false }) inline_for_extraction [@@noextract_to "krml"] let array_ref_of (#t: Type) (#td: typedef t) (ar: array td) : Tot (array_ref td) = array_ptr_of ar inline_for_extraction [@@noextract_to "krml"] let mk_array (#t: Type) (#td: typedef t) (a: array_ref td) (len: array_len_t a) : Tot (array td) = mk_array_or_null a len let array_length (#t: Type) (#td: typedef t) (a: array td) : GTot nat = SZ.v (dsnd a) val array_pts_to (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : Tot vprop let array_pts_to_or_null (#t: Type) (#td: typedef t) (r: array_or_null td) (v: Ghost.erased (Seq.seq t)) : Tot vprop = if g_array_is_null r then emp else array_pts_to r v [@@noextract_to "krml"] // primitive val array_ptr_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_ptr td) (len: array_len_t r) // : STAtomicBase bool false opened Unobservable : stt bool (array_pts_to_or_null (mk_array_or_null r len) v) (fun b -> array_pts_to_or_null (mk_array_or_null r len) v ** pure ( b == g_array_is_null (mk_array_or_null r len) )) #set-options "--print_implicits" inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_is_null (#t: Type) // (#opened: _) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: array_or_null td) // : STAtomicBase bool false opened Unobservable requires (array_pts_to_or_null r v) returns b: bool ensures (array_pts_to_or_null r v ** pure ( b == g_array_is_null r )) { let a = array_ptr_of r; let len : array_len_t a = array_len_of r; rewrite (array_pts_to_or_null r v) as (array_pts_to_or_null (mk_array_or_null a len) v); let res = array_ptr_is_null a len; rewrite (array_pts_to_or_null (mk_array_or_null a len) v) as (array_pts_to_or_null r v); res } ``` val array_pts_to_length (#t: Type) (#td: typedef t) (r: array td) (v: Ghost.erased (Seq.seq t)) : stt_ghost unit (array_pts_to r v) (fun _ -> array_pts_to r v ** pure ( Seq.length v == SZ.v (dsnd r) )) #set-options "--print_implicits" let has_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a: array td) : GTot prop = let (| al, len |) = a in array_ref_base_size al == n /\ has_array_ref_base al #tn r /\ array_ref_offset al == 0sz /\ Ghost.reveal len == n let has_array_of_base_inj (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (r: ref (base_array0 tn td n)) (a1 a2: array td) : Lemma (requires ( has_array_of_base #t #tn #n #td r a1 /\ has_array_of_base #t #tn #n #td r a2 )) (ensures (a1 == a2)) = let (| ar1, _ |) = a1 in let (| ar2, _ |) = a2 in array_ref_base_offset_inj #t #td #tn ar1 r ar2 r let seq_of_base_array (#t: Type) (#tn: Type) (#n: array_size_t) (v: base_array_t t tn n) : GTot (Seq.lseq t (SZ.v n)) = Seq.init_ghost (SZ.v n) (fun i -> base_array_index v (SZ.uint_to_t i)) val ghost_array_of_base_focus (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost unit (pts_to r v ** pure ( has_array_of_base r a )) (fun _ -> array_pts_to a (seq_of_base_array v)) val ghost_array_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) : stt_ghost (a: Ghost.erased (array td) { has_array_of_base r a }) (pts_to r v) (fun a -> array_pts_to a (seq_of_base_array v)) let array_ref_of_base_post (#t: Type) (#tn: Type0) (#n: Ghost.erased array_size_t) (#td: typedef t) (v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) (a: array_ref td) (ar: array td) : GTot prop = array_ptr_of ar == a /\ array_ref_base_size a == Ghost.reveal n /\ array_ref_offset a == 0sz /\ has_array_of_base r ar /\ Ghost.reveal (dsnd ar) == Ghost.reveal n // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) //: STAtomicBase (array_ref td) false opened Unobservable : stt (array_ref td) (pts_to r v) (fun a -> exists* (ar: array td) . array_pts_to ar (seq_of_base_array v) ** pure ( array_ref_of_base_post v r a ar )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_of_base (#t: Type) (#tn: Type0) // (#opened: _) (#n: Ghost.erased array_size_t) (#td: typedef t) (#v: Ghost.erased (base_array_t t tn n)) (r: ref (base_array0 tn td n)) // : STAtomicBase (a: array td { has_array_of_base r a }) false opened Unobservable requires (pts_to r v) returns a: (a: array td { has_array_of_base r a }) ensures (array_pts_to a (seq_of_base_array v)) { let al = array_ref_of_base r; with ga . assert (array_pts_to #t #td ga (seq_of_base_array v)); let a = mk_array_or_null al (Ghost.hide (n <: SZ.t)); rewrite (array_pts_to ga (seq_of_base_array v)) as (array_pts_to a (seq_of_base_array v)); a } ``` val unarray_of_base (#t: Type) (#tn: Type0) (#n: array_size_t) (#td: typedef t) (#v: Ghost.erased (Seq.seq t)) (r: ref (base_array0 tn td n)) (a: array td) : stt_ghost (Ghost.erased (base_array_t t tn n)) (array_pts_to a v ** pure ( has_array_of_base r a )) (fun v' -> pts_to r v' ** pure ( Ghost.reveal v `Seq.equal` seq_of_base_array v' )) val freeable_array (#t: Type) (#td: typedef t) (a: array td) : Tot vprop let freeable_or_null_array (#t: Type) (#td: typedef t) (a: array_or_null td) : Tot vprop = if g_array_is_null a then emp else freeable_array a [@@noextract_to "krml"] // primitive val array_ptr_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) : stt (array_ptr td) emp (fun a -> exists* (ar: array_or_null td) (s: Seq.seq t) . freeable_or_null_array ar ** array_pts_to_or_null ar s ** pure ( array_ptr_of ar == a /\ (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s `Seq.equal` FStar.Seq.create (SZ.v sz) (uninitialized td) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_alloc (#t: Type) (td: typedef t) (sz: SZ.t { SZ.v sz > 0 }) requires emp returns ar: array_or_null td ensures ( freeable_or_null_array ar ** ( exists* s . array_pts_to_or_null ar s ** pure ( (g_array_is_null ar == false ==> array_length ar == SZ.v sz) /\ Ghost.reveal s == FStar.Seq.create (SZ.v sz) (uninitialized td) ))) { let a : array_ptr td = array_ptr_alloc td sz; with ar' s . assert (freeable_or_null_array ar' ** array_pts_to_or_null #_ #td ar' s); let len: array_len_t a = array_len_of ar'; let ar = mk_array_or_null a len; rewrite (array_pts_to_or_null ar' s) as (array_pts_to_or_null ar s); rewrite (freeable_or_null_array ar') as (freeable_or_null_array ar); ar } ``` let full_seq (#t: Type) (td: typedef t) (v: Seq.seq t) : GTot prop = forall (i: nat { i < Seq.length v }) . {:pattern (Seq.index v i)} full td (Seq.index v i) let full_seq_seq_of_base_array (#t: Type0) (tn: Type0) (td: typedef t) (#n: array_size_t) (b: base_array_t t tn n) : Lemma (ensures (full_seq td (seq_of_base_array b) <==> full (base_array0 tn td n) b)) [SMTPat (full_seq td (seq_of_base_array b))] = assert (forall (i: base_array_index_t n) . base_array_index b i == Seq.index (seq_of_base_array b) (SZ.v i)) [@@noextract_to "krml"] // primitive val array_ref_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (n: array_len_t a) : stt unit (freeable_array (mk_array a n) ** array_pts_to (mk_array a n) s ** pure ( full_seq td s )) (fun _ -> emp) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_free (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) requires (freeable_array a ** array_pts_to a s ** pure ( full_seq td s )) ensures emp { let al = array_ptr_of a; let n: array_len_t al = array_len_of a; rewrite (freeable_array a) as (freeable_array (mk_array al n)); rewrite (array_pts_to a s) as (array_pts_to (mk_array al n) s); array_ref_free al n } ``` (* val has_array_of_ref (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : Tot vprop val has_array_of_ref_post (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : STGhost unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a) (True) (fun _ -> let (| al, len |) = a in array_ref_base_size al == 1sz /\ array_ref_offset al == 0sz /\ Ghost.reveal len == 1sz ) // val has_array_of_ref_inj // (#t: Type) // (#td: typedef t) // (r: ref td) // (a1 a2: array td) // : Lemma // (requires ( // has_array_of_ref r a1 /\ // has_array_of_ref r a2 // )) // (ensures a1 == a2) val ghost_array_of_ref_focus (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) (a: array td) : stt_ghost unit opened (pts_to r v ** has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** array_pts_to a (Seq.create 1 (Ghost.reveal v))) val ghost_array_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt_ghost (Ghost.erased (array td)) opened (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) // to be extracted to just r [@@noextract_to "krml"] // primitive val array_ref_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (a: array_ref td { array_ref_base_size a == 1sz /\ array_ref_offset a == 0sz }) (pts_to r v) (fun a -> array_pts_to (| a, Ghost.hide 1sz |) (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r (| a, Ghost.hide 1sz |)) inline_for_extraction [@@noextract_to "krml"] let array_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (r: ref td) : stt (array td) (pts_to r v) (fun a -> array_pts_to a (Seq.create 1 (Ghost.reveal v)) ** has_array_of_ref r a) = let al = array_ref_of_ref r in let a : array td = (| al, Ghost.hide 1sz |) in rewrite (array_pts_to _ _) (array_pts_to _ _); rewrite (has_array_of_ref _ _) (has_array_of_ref r a); return a val unarray_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (r: ref td) (a: array td) : stt_ghost (squash (Seq.length s == 1)) opened (array_pts_to a s ** has_array_of_ref r a) (fun _ -> pts_to r (Seq.index s 0) ** has_array_of_ref r a) *) val has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) : Tot vprop (* = SZ.v i < SZ.v (dsnd a) /\ has_base_array_cell (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r *) val has_array_cell_post (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r': ref td) : stt_ghost unit (has_array_cell a i r') (fun _ -> has_array_cell a i r' ** pure ( SZ.v i < SZ.v (dsnd a) )) val has_array_cell_has_base_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_array_cell a i r ** pure ( has_array_ref_base (array_ptr_of a) br )) (fun j -> has_base_array_cell br j r ** pure ( SZ.v j == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v i )) val has_base_array_cell_has_array_cell (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r: ref td) (#ty: Type) (br: ref (base_array0 ty td (array_ref_base_size (array_ptr_of a)))) : stt_ghost (Ghost.erased SZ.t) (has_base_array_cell br i r ** pure ( has_array_ref_base (array_ptr_of a) br /\ SZ.v i >= SZ.v (array_ref_offset (array_ptr_of a)) /\ SZ.v i < SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v (dsnd a) )) (fun j -> has_array_cell a j r ** pure ( SZ.v i == SZ.v (array_ref_offset (array_ptr_of a)) + SZ.v j )) val has_array_cell_inj (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) (r1 r2: ref td) : stt_ghost unit ( has_array_cell a i r1 ** has_array_cell a i r2 ) (fun _ -> has_array_cell a i r1 ** has_array_cell a i r2 ** ref_equiv r1 r2 ) // = has_base_array_cell_inj (array_ref_base (array_ptr_of a)) (array_ref_offset (array_ptr_of a) `SZ.add` i) r1 r2 (* val has_array_cell_array_of_ref (#opened: _) (#t: Type) (#td: typedef t) (r: ref td) (a: array td) : SteelGhostT unit opened (has_array_of_ref r a) (fun _ -> has_array_of_ref r a ** has_array_cell a 0sz r) *) val ghost_array_cell_focus (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** has_array_cell a i r) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) val ghost_array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (r: Ghost.erased (ref td) { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) (fun r -> array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) [@@noextract_to "krml"] // primitive val array_ref_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array_ref td) (len: array_len_t a) (i: SZ.t) : stt (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v len }) (array_pts_to (mk_array a len) s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v len )) (fun r -> array_pts_to (mk_array a len) (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell (mk_array a len) i r) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) requires (array_pts_to a s ** pure ( SZ.v i < Seq.length s \/ SZ.v i < SZ.v (dsnd a) )) returns r: (r: ref td { SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a) }) ensures (array_pts_to a (Seq.upd s (SZ.v i) (unknown td)) ** pts_to r (Seq.index s (SZ.v i)) ** has_array_cell a i r) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let r = array_ref_cell al len i; rewrite (array_pts_to (mk_array al len) (Seq.upd s (SZ.v i) (unknown td))) as (array_pts_to a (Seq.upd s (SZ.v i) (unknown td))); rewrite (has_array_cell (mk_array al len) i r) as (has_array_cell a i r); r } ``` val unarray_cell (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (#v: Ghost.erased t) (a: array td) (i: SZ.t) (r: ref td) : stt_ghost (squash (SZ.v i < Seq.length s /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pts_to r v ** has_array_cell a i r ** pure ( SZ.v i < Seq.length s ==> Seq.index s (SZ.v i) == unknown td )) (fun _ -> array_pts_to a (Seq.upd s (SZ.v i) v) ** has_array_cell a i r) val array_ref_shift (#t: Type) (#td: typedef t) (a: array_ref td) (i: SZ.t) : Ghost (array_ref td) (requires (SZ.v (array_ref_offset a) + SZ.v i <= SZ.v (array_ref_base_size a))) (ensures (fun y -> array_ref_base_size y == array_ref_base_size a /\ (forall ty r . has_array_ref_base a #ty r ==> has_array_ref_base y #ty (coerce_eq () r)) /\ array_ref_offset y == array_ref_offset a `SZ.add` i )) val array_ref_shift_zero (#t: Type) (#td: typedef t) (a: array_ref td) : Lemma (ensures ( array_ref_shift a 0sz == a )) val array_ref_shift_assoc (#t: Type) (#td: typedef t) (a: array_ref td) (i1 i2: SZ.t) : Lemma (requires (SZ.v (array_ref_offset a) + SZ.v i1 + SZ.v i2 <= SZ.v (array_ref_base_size a))) (ensures ( array_ref_shift a (SZ.add i1 i2) == array_ref_shift (array_ref_shift a i1) i2 )) inline_for_extraction [@@noextract_to "krml"] let array_split_l (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Pure (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, _ |) = a in (| al, Ghost.hide i |) let array_split_r (#t: Type) (#td: typedef t) (a: array td) (i: SZ.t) : Ghost (array td) (requires (SZ.v i <= SZ.v (dsnd a))) (ensures (fun _ -> True)) = let (| al, len |) = a in (| array_ref_shift al i, Ghost.hide (len `SZ.sub` i) |) val ghost_array_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) : stt_ghost (squash (SZ.v i <= SZ.v (dsnd a) /\ Seq.length s == SZ.v (dsnd a))) (array_pts_to a s ** pure ( SZ.v i <= SZ.v (dsnd a) \/ SZ.v i <= Seq.length s )) (fun _ -> array_pts_to (array_split_l a i) (Seq.slice s 0 (SZ.v i)) ** array_pts_to (array_split_r a i) (Seq.slice s (SZ.v i) (Seq.length s))) let array_ref_split_post (#t: Type) (#td: typedef t) (s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t) (sl sr: Ghost.erased (Seq.seq t)) : GTot prop = SZ.v i <= array_length a /\ Seq.length s == array_length a /\ Ghost.reveal sl == Seq.slice s 0 (SZ.v i) /\ Ghost.reveal sr == Seq.slice s (SZ.v i) (Seq.length s) [@@noextract_to "krml"] // primitive val array_ref_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (al: array_ref td) (len: array_len_t al) (i: SZ.t { SZ.v i <= SZ.v len }) : stt (array_ref td) (array_pts_to (mk_array al len) s) (fun ar -> exists* sl sr . array_pts_to (array_split_l (mk_array al len) i) sl ** array_pts_to (array_split_r (mk_array al len) i) sr ** pure ( array_ref_split_post s (mk_array al len) i sl sr /\ SZ.v i <= SZ.v len /\ SZ.v i <= Seq.length s /\ ar == array_ptr_of (array_split_r (mk_array al len) i) )) inline_for_extraction [@@noextract_to "krml"] ```pulse fn array_split (#t: Type) (#td: typedef t) (#s: Ghost.erased (Seq.seq t)) (a: array td) (i: SZ.t { SZ.v i <= array_length a }) requires (array_pts_to a s) returns a': array td ensures (exists* sl sr . array_pts_to (array_split_l a i) sl ** array_pts_to a' sr ** pure ( array_ref_split_post s a i sl sr /\ SZ.v i <= array_length a /\ SZ.v i <= Seq.length s /\ a' == array_split_r a i )) { let al = array_ptr_of a; let len = array_len_of a; rewrite (array_pts_to a s) as (array_pts_to (mk_array al len) s); let ar = array_ref_split al len i; with sl sr . assert ( array_pts_to (array_split_l (mk_array al len) i) sl ** array_pts_to (array_split_r (mk_array al len) i) sr ); let a' = mk_array ar (Ghost.hide (len `SZ.sub` i)); rewrite (array_pts_to (array_split_l (mk_array al len) i) sl) as (array_pts_to (array_split_l a i) sl); rewrite (array_pts_to (array_split_r (mk_array al len) i) sr) as (array_pts_to a' sr); a' } ``` val array_join (#t: Type) (#td: typedef t) (#sl #sr: Ghost.erased (Seq.seq t)) (a al ar: array td) (i: SZ.t) : stt_ghost unit (array_pts_to al sl ** array_pts_to ar sr ** pure ( SZ.v i <= SZ.v (dsnd a) /\ al == array_split_l a i /\ ar == array_split_r a i )) (fun _ -> array_pts_to a (sl `Seq.append` sr)) let fractionable_seq (#t: Type) (td: typedef t) (s: Seq.seq t) : GTot prop = forall (i: nat). i < Seq.length s ==> fractionable td (Seq.index s i) let mk_fraction_seq (#t: Type) (td: typedef t) (s: Seq.seq t) (p: perm) : Ghost (Seq.seq t) (requires (fractionable_seq td s)) (ensures (fun _ -> True)) = Seq.init_ghost (Seq.length s) (fun i -> mk_fraction td (Seq.index s i) p)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.C.Types.Base.fsti.checked", "Pulse.C.Types.Array.Base.fst.checked", "Pulse.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.C.Types.Array.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Pulse.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Pulse.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
td: Pulse.C.Types.Base.typedef t -> x: FStar.Seq.Base.seq t -> FStar.Pervasives.Lemma (requires Pulse.C.Types.Array.fractionable_seq td x) (ensures Pulse.C.Types.Array.mk_fraction_seq td x PulseCore.FractionalPermission.full_perm == x) [SMTPat (Pulse.C.Types.Array.mk_fraction_seq td x PulseCore.FractionalPermission.full_perm)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Pulse.C.Types.Base.typedef", "FStar.Seq.Base.seq", "Prims._assert", "FStar.Seq.Base.equal", "Pulse.C.Types.Array.mk_fraction_seq", "PulseCore.FractionalPermission.full_perm", "Prims.unit", "Pulse.C.Types.Array.fractionable_seq", "Prims.squash", "Prims.eq2", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let mk_fraction_seq_full (#t: Type0) (td: typedef t) (x: Seq.seq t) : Lemma (requires (fractionable_seq td x)) (ensures (mk_fraction_seq td x full_perm == x)) [SMTPat (mk_fraction_seq td x full_perm)] =
assert ((mk_fraction_seq td x full_perm) `Seq.equal` x)
false
DM4F_layered.fst
DM4F_layered.ite_wp
val ite_wp (#a #st: _) (b: bool) (w1 w2: wp st a) : wp st a
val ite_wp (#a #st: _) (b: bool) (w1 w2: wp st a) : wp st a
let ite_wp #a #st (b:bool) (w1 w2 : wp st a) : wp st a = fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p)
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 89, "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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); } let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Prims.bool -> w1: DM4F_layered.wp st a -> w2: DM4F_layered.wp st a -> DM4F_layered.wp st a
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "DM4F_layered.wp", "DM4F_layered.post_t", "Prims.l_and", "Prims.l_imp", "Prims.b2t", "Prims.l_not", "Prims.logical" ]
[]
false
false
false
true
false
let ite_wp #a #st (b: bool) (w1: wp st a) (w2: wp st a) : wp st a =
fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p)
false
DM4F_layered.fst
DM4F_layered.lift_id_st
val lift_id_st (a wp st: _) (f: ID2.repr a wp) : repr a st (lift_id_st_wp wp)
val lift_id_st (a wp st: _) (f: ID2.repr a wp) : repr a st (lift_id_st_wp wp)
let lift_id_st a wp st (f : ID2.repr a wp) : repr a st (lift_id_st_wp wp) = elim_pure_wp_monotonicity_forall (); fun s0 -> (f (), s0)
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 137, "start_col": 0, "start_line": 134 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); } let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1 let ite_wp #a #st (b:bool) (w1 w2 : wp st a) : wp st a = fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p) let if_then_else (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) (g : repr a st wpg) (b : bool) : Type = repr a st (ite_wp b wpf wpg) let stronger (#a:Type) (#st:Type0) (w1 w2 : wp st a) : Type0 = forall s0 p. w1 s0 p ==> w2 s0 p let subcomp (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True)) = f total reifiable reflectable effect { ST (a:Type) ([@@@ effect_param] st:Type0) (_:wp st a) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_st_wp #a #st (w : pure_wp a) : wp st a = FStar.Monotonic.Pure.elim_pure_wp_monotonicity w; let r = fun s0 p -> w (fun x -> p x s0) in r let lift_id_st_wp #a #st (w : pure_wp a) : wp st a = elim_pure_wp_monotonicity_forall (); fun s0 p -> w (fun x -> p x s0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Type -> wp: Prims.pure_wp a -> st: Type0 -> f: ID2.repr a wp -> DM4F_layered.repr a st (DM4F_layered.lift_id_st_wp wp)
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "ID2.repr", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall", "DM4F_layered.repr", "DM4F_layered.lift_id_st_wp" ]
[]
false
false
false
false
false
let lift_id_st a wp st (f: ID2.repr a wp) : repr a st (lift_id_st_wp wp) =
elim_pure_wp_monotonicity_forall (); fun s0 -> (f (), s0)
false
DM4F_layered.fst
DM4F_layered.lift_pure_st_wp
val lift_pure_st_wp (#a #st: _) (w: pure_wp a) : wp st a
val lift_pure_st_wp (#a #st: _) (w: pure_wp a) : wp st a
let lift_pure_st_wp #a #st (w : pure_wp a) : wp st a = FStar.Monotonic.Pure.elim_pure_wp_monotonicity w; let r = fun s0 p -> w (fun x -> p x s0) in r
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 128, "start_col": 0, "start_line": 125 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); } let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1 let ite_wp #a #st (b:bool) (w1 w2 : wp st a) : wp st a = fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p) let if_then_else (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) (g : repr a st wpg) (b : bool) : Type = repr a st (ite_wp b wpf wpg) let stronger (#a:Type) (#st:Type0) (w1 w2 : wp st a) : Type0 = forall s0 p. w1 s0 p ==> w2 s0 p let subcomp (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True)) = f total reifiable reflectable effect { ST (a:Type) ([@@@ effect_param] st:Type0) (_:wp st a) with {repr; return; bind; subcomp; if_then_else} }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
w: Prims.pure_wp a -> DM4F_layered.wp st a
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.l_True", "Prims.pure_pre", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity", "DM4F_layered.wp" ]
[]
false
false
false
true
false
let lift_pure_st_wp #a #st (w: pure_wp a) : wp st a =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity w; let r = fun s0 p -> w (fun x -> p x s0) in r
false
DM4F_layered.fst
DM4F_layered.test
val test: Prims.unit -> ST int int null
val test: Prims.unit -> ST int int null
let test () : ST int int null = let x = get () in put (x + x); get () + get ()
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 153, "start_col": 0, "start_line": 150 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); } let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1 let ite_wp #a #st (b:bool) (w1 w2 : wp st a) : wp st a = fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p) let if_then_else (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) (g : repr a st wpg) (b : bool) : Type = repr a st (ite_wp b wpf wpg) let stronger (#a:Type) (#st:Type0) (w1 w2 : wp st a) : Type0 = forall s0 p. w1 s0 p ==> w2 s0 p let subcomp (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True)) = f total reifiable reflectable effect { ST (a:Type) ([@@@ effect_param] st:Type0) (_:wp st a) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_st_wp #a #st (w : pure_wp a) : wp st a = FStar.Monotonic.Pure.elim_pure_wp_monotonicity w; let r = fun s0 p -> w (fun x -> p x s0) in r let lift_id_st_wp #a #st (w : pure_wp a) : wp st a = elim_pure_wp_monotonicity_forall (); fun s0 p -> w (fun x -> p x s0) let lift_id_st a wp st (f : ID2.repr a wp) : repr a st (lift_id_st_wp wp) = elim_pure_wp_monotonicity_forall (); fun s0 -> (f (), s0) sub_effect ID ~> ST = lift_id_st let null #st #a : wp st a = fun s0 p -> forall x s1. p x s1 let get #st () : ST st st (fun s0 p -> p s0 s0) = ST?.reflect (fun s0 -> (s0, s0)) let put #st (s:st) : ST unit st (fun _ p -> p () s) = ST?.reflect (fun _ -> ((), s))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> DM4F_layered.ST Prims.int
DM4F_layered.ST
[]
[]
[ "Prims.unit", "Prims.op_Addition", "Prims.int", "DM4F_layered.get", "DM4F_layered.put", "DM4F_layered.null" ]
[]
false
true
false
false
false
let test () : ST int int null =
let x = get () in put (x + x); get () + get ()
false
DM4F_layered.fst
DM4F_layered.null
val null (#st #a: _) : wp st a
val null (#st #a: _) : wp st a
let null #st #a : wp st a = fun s0 p -> forall x s1. p x s1
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 142, "start_col": 0, "start_line": 141 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); } let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1 let ite_wp #a #st (b:bool) (w1 w2 : wp st a) : wp st a = fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p) let if_then_else (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) (g : repr a st wpg) (b : bool) : Type = repr a st (ite_wp b wpf wpg) let stronger (#a:Type) (#st:Type0) (w1 w2 : wp st a) : Type0 = forall s0 p. w1 s0 p ==> w2 s0 p let subcomp (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True)) = f total reifiable reflectable effect { ST (a:Type) ([@@@ effect_param] st:Type0) (_:wp st a) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_st_wp #a #st (w : pure_wp a) : wp st a = FStar.Monotonic.Pure.elim_pure_wp_monotonicity w; let r = fun s0 p -> w (fun x -> p x s0) in r let lift_id_st_wp #a #st (w : pure_wp a) : wp st a = elim_pure_wp_monotonicity_forall (); fun s0 p -> w (fun x -> p x s0) let lift_id_st a wp st (f : ID2.repr a wp) : repr a st (lift_id_st_wp wp) = elim_pure_wp_monotonicity_forall (); fun s0 -> (f (), s0) sub_effect ID ~> ST = lift_id_st
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
DM4F_layered.wp st a
Prims.Tot
[ "total" ]
[]
[ "Prims.l_Forall", "Prims.logical", "DM4F_layered.wp" ]
[]
false
false
false
true
false
let null #st #a : wp st a =
fun s0 p -> forall x s1. p x s1
false
DM4F_layered.fst
DM4F_layered.put
val put (#st: _) (s: st) : ST unit st (fun _ p -> p () s)
val put (#st: _) (s: st) : ST unit st (fun _ p -> p () s)
let put #st (s:st) : ST unit st (fun _ p -> p () s) = ST?.reflect (fun _ -> ((), s))
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 148, "start_col": 0, "start_line": 147 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); } let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1 let ite_wp #a #st (b:bool) (w1 w2 : wp st a) : wp st a = fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p) let if_then_else (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) (g : repr a st wpg) (b : bool) : Type = repr a st (ite_wp b wpf wpg) let stronger (#a:Type) (#st:Type0) (w1 w2 : wp st a) : Type0 = forall s0 p. w1 s0 p ==> w2 s0 p let subcomp (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True)) = f total reifiable reflectable effect { ST (a:Type) ([@@@ effect_param] st:Type0) (_:wp st a) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_st_wp #a #st (w : pure_wp a) : wp st a = FStar.Monotonic.Pure.elim_pure_wp_monotonicity w; let r = fun s0 p -> w (fun x -> p x s0) in r let lift_id_st_wp #a #st (w : pure_wp a) : wp st a = elim_pure_wp_monotonicity_forall (); fun s0 p -> w (fun x -> p x s0) let lift_id_st a wp st (f : ID2.repr a wp) : repr a st (lift_id_st_wp wp) = elim_pure_wp_monotonicity_forall (); fun s0 -> (f (), s0) sub_effect ID ~> ST = lift_id_st let null #st #a : wp st a = fun s0 p -> forall x s1. p x s1 let get #st () : ST st st (fun s0 p -> p s0 s0) = ST?.reflect (fun s0 -> (s0, s0))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: st -> DM4F_layered.ST Prims.unit
DM4F_layered.ST
[]
[]
[ "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "FStar.Pervasives.Native.tuple2" ]
[]
false
true
false
false
false
let put #st (s: st) : ST unit st (fun _ p -> p () s) =
ST?.reflect (fun _ -> ((), s))
false
DM4F_layered.fst
DM4F_layered.get
val get: #st: _ -> Prims.unit -> ST st st (fun s0 p -> p s0 s0)
val get: #st: _ -> Prims.unit -> ST st st (fun s0 p -> p s0 s0)
let get #st () : ST st st (fun s0 p -> p s0 s0) = ST?.reflect (fun s0 -> (s0, s0))
{ "file_name": "examples/layeredeffects/DM4F_layered.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 145, "start_col": 0, "start_line": 144 }
(* 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 DM4F_layered (* Same as DM4F, but layered over a layered PURE *) open DM4F_Utils open ID2 open FStar.Tactics.V2 (* Simulating state effect in DM4F, hopefully doable by a tactic. *) type post_t st a = a -> st -> Type0 type wp0 (st:Type u#0) (a:Type u#ua) : Type u#(max 1 ua) = st -> post_t st a -> Type0 let st_monotonic #st #a (w : wp0 st a) : Type0 = //forall s0 p1 p2. (forall r. p1 r ==> p2 r) ==> w s0 p1 ==> w s0 p2 // ^ this version seems to be less SMT-friendly forall s0 p1 p2. (forall x s1. p1 x s1 ==> p2 x s1) ==> w s0 p1 ==> w s0 p2 type wp st a = w:(wp0 st a){st_monotonic w} open FStar.Monotonic.Pure type repr (a:Type u#ua) (st:Type0) (wp : wp u#ua st a) : Type u#ua = s0:st -> ID (a & st) (as_pure_wp (fun p -> wp s0 (curry p))) unfold let return_wp (#a:Type) (#st:Type0) (x:a) : wp st a = fun s0 p -> p x s0 let return (a:Type) (x:a) (st:Type0) : repr a st (return_wp x) = fun s0 -> (x, s0) unfold let bind_wp (#a:Type) (#b:Type) (#st:Type0) (w1 : wp st a) (w2 : a -> wp st b) : wp st b = fun s0 p -> w1 s0 (fun y s1 -> w2 y s1 p) let squash_lem a : Lemma (a ==> squash a) = () let elim_mon #a #st (w : wp st a) (p1 p2 : post_t st a) (s0:st) : Lemma (requires (forall x s1. p1 x s1 ==> p2 x s1)) (ensures w s0 p1 ==> w s0 p2) = () (* All of this is needed due to an auto_squash popping up in the VC *) let wp_squash_lem #a #st (w : wp st a) (p : post_t st a) (s0:st) : Lemma (requires w s0 p) (ensures w s0 (fun x y -> squash (p x y))) = calc (==>) { w s0 p; ==> {} w s0 (fun x y -> p x y); ==> { elim_mon w (fun x y -> p x y) (fun x y -> squash (p x y)) s0 } // grr w s0 (fun x y -> squash (p x y)); } let bind (a:Type) (b:Type) (st:Type0) (wp_c : wp st a) (wp_f : a -> wp st b) (c : repr a st wp_c) (f : (x:a -> repr b st (wp_f x))) : repr b st (bind_wp wp_c wp_f) by (explode (); let w = nth_var 3 in apply_lemma (`(wp_squash_lem (`#(binding_to_term w)))); dump "") = fun s0 -> let (y, s1) = c s0 in f y s1 let ite_wp #a #st (b:bool) (w1 w2 : wp st a) : wp st a = fun s0 p -> (b ==> w1 s0 p) /\ ((~b) ==> w2 s0 p) let if_then_else (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) (g : repr a st wpg) (b : bool) : Type = repr a st (ite_wp b wpf wpg) let stronger (#a:Type) (#st:Type0) (w1 w2 : wp st a) : Type0 = forall s0 p. w1 s0 p ==> w2 s0 p let subcomp (a:Type) (st:Type0) (wpf wpg : wp st a) (f : repr a st wpf) : Pure (repr a st wpg) (requires (stronger wpg wpf)) (ensures (fun _ -> True)) = f total reifiable reflectable effect { ST (a:Type) ([@@@ effect_param] st:Type0) (_:wp st a) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_st_wp #a #st (w : pure_wp a) : wp st a = FStar.Monotonic.Pure.elim_pure_wp_monotonicity w; let r = fun s0 p -> w (fun x -> p x s0) in r let lift_id_st_wp #a #st (w : pure_wp a) : wp st a = elim_pure_wp_monotonicity_forall (); fun s0 p -> w (fun x -> p x s0) let lift_id_st a wp st (f : ID2.repr a wp) : repr a st (lift_id_st_wp wp) = elim_pure_wp_monotonicity_forall (); fun s0 -> (f (), s0) sub_effect ID ~> ST = lift_id_st let null #st #a : wp st a = fun s0 p -> forall x s1. p x s1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "ID2.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Calc.fsti.checked", "DM4F_Utils.fst.checked" ], "interface_file": false, "source_file": "DM4F_layered.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "ID2", "short_module": null }, { "abbrev": false, "full_module": "DM4F_Utils", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> DM4F_layered.ST st
DM4F_layered.ST
[]
[]
[ "Prims.unit", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2" ]
[]
false
true
false
false
false
let get #st () : ST st st (fun s0 p -> p s0 s0) =
ST?.reflect (fun s0 -> (s0, s0))
false
Lib.IntTypes.fst
Lib.IntTypes.eq_mask_lemma_signed
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma (if v a = v b then v (eq_mask a b) == ones_v t else v (eq_mask a b) == 0)
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma (if v a = v b then v (eq_mask a b) == ones_v t else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b = match t with | S8 -> begin assert_norm (pow2 8 = 2 * pow2 7); if 0 <= v a then modulo_lemma (v a) (pow2 8) else begin modulo_addition_lemma (v a) 1 (pow2 8); modulo_lemma (v a + pow2 8) (pow2 8) end end | S16 -> begin assert_norm (pow2 16 = 2 * pow2 15); if 0 <= v a then modulo_lemma (v a) (pow2 16) else begin modulo_addition_lemma (v a) 1 (pow2 16); modulo_lemma (v a + pow2 16) (pow2 16) end end | S32 -> begin if 0 <= v a then modulo_lemma (v a) (pow2 32) else begin modulo_addition_lemma (v a) 1 (pow2 32); modulo_lemma (v a + pow2 32) (pow2 32) end end | S64 -> begin if 0 <= v a then modulo_lemma (v a) (pow2 64) else begin modulo_addition_lemma (v a) 1 (pow2 64); modulo_lemma (v a + pow2 64) (pow2 64) end end
{ "file_name": "lib/Lib.IntTypes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 7, "end_line": 860, "start_col": 0, "start_line": 821 }
module Lib.IntTypes open FStar.Math.Lemmas #push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200" let pow2_2 _ = assert_norm (pow2 2 = 4) let pow2_3 _ = assert_norm (pow2 3 = 8) let pow2_4 _ = assert_norm (pow2 4 = 16) let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000) let bits_numbytes t = () let sec_int_t t = pub_int_t t let sec_int_v #t u = pub_int_v u let secret #t x = x [@(strict_on_arguments [0])] let mk_int #t #l x = match t with | U1 -> UInt8.uint_to_t x | U8 -> UInt8.uint_to_t x | U16 -> UInt16.uint_to_t x | U32 -> UInt32.uint_to_t x | U64 -> UInt64.uint_to_t x | U128 -> UInt128.uint_to_t x | S8 -> Int8.int_to_t x | S16 -> Int16.int_to_t x | S32 -> Int32.int_to_t x | S64 -> Int64.int_to_t x | S128 -> Int128.int_to_t x val v_extensionality: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma (requires v a == v b) (ensures a == b) let v_extensionality #t #l a b = match t with | U1 -> () | U8 -> UInt8.v_inj a b | U16 -> UInt16.v_inj a b | U32 -> UInt32.v_inj a b | U64 -> UInt64.v_inj a b | U128 -> UInt128.v_inj a b | S8 -> Int8.v_inj a b | S16 -> Int16.v_inj a b | S32 -> Int32.v_inj a b | S64 -> Int64.v_inj a b | S128 -> Int128.v_inj a b let v_injective #t #l a = v_extensionality a (mk_int (v a)) let v_mk_int #t #l n = () let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n) // KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided // We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals let i128 n = assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1)); sint #S128 #SEC n let size_to_uint32 x = x let size_to_uint64 x = Int.Cast.uint32_to_uint64 x let byte_to_uint8 x = x let byte_to_int8 x = Int.Cast.uint8_to_int8 x let op_At_Percent = Int.op_At_Percent // FStar.UInt128 gets special treatment in KaRaMeL. There is no // equivalent for FStar.Int128 at the moment, so we use the three // assumed cast operators below. // // Using them will fail at runtime with an informative message. // The commented-out implementations show that they are realizable. // // When support for `FStar.Int128` is added KaRaMeL, these casts must // be added as special cases. When using builtin compiler support for // `int128_t`, they can be implemented directly as C casts without // undefined or implementation-defined behaviour. assume val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a} //let uint128_to_int128 a = Int128.int_to_t (v a) assume val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128} //let int128_to_uint128 a = mk_int (v a % pow2 128) assume val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a} //let int64_to_int128 a = Int128.int_to_t (v a) val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a} let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a) val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128} let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a) val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64} let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a) #push-options "--z3rlimit 1000" [@(strict_on_arguments [0;2])] let cast #t #l t' l' u = assert_norm (pow2 8 = 2 * pow2 7); assert_norm (pow2 16 = 2 * pow2 15); assert_norm (pow2 64 * pow2 64 = pow2 128); assert_norm (pow2 16 * pow2 48 = pow2 64); assert_norm (pow2 8 * pow2 56 = pow2 64); assert_norm (pow2 32 * pow2 32 = pow2 64); modulo_modulo_lemma (v u) (pow2 32) (pow2 32); modulo_modulo_lemma (v u) (pow2 64) (pow2 64); modulo_modulo_lemma (v u) (pow2 128) (pow2 64); modulo_modulo_lemma (v u) (pow2 16) (pow2 48); modulo_modulo_lemma (v u) (pow2 8) (pow2 56); let open FStar.Int.Cast in let open FStar.Int.Cast.Full in match t, t' with | U1, U1 -> u | U1, U8 -> u | U1, U16 -> uint8_to_uint16 u | U1, U32 -> uint8_to_uint32 u | U1, U64 -> uint8_to_uint64 u | U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u) | U1, S8 -> uint8_to_int8 u | U1, S16 -> uint8_to_int16 u | U1, S32 -> uint8_to_int32 u | U1, S64 -> uint8_to_int64 u | U1, S128 -> uint64_to_int128 (uint8_to_uint64 u) | U8, U1 -> UInt8.rem u 2uy | U8, U8 -> u | U8, U16 -> uint8_to_uint16 u | U8, U32 -> uint8_to_uint32 u | U8, U64 -> uint8_to_uint64 u | U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u) | U8, S8 -> uint8_to_int8 u | U8, S16 -> uint8_to_int16 u | U8, S32 -> uint8_to_int32 u | U8, S64 -> uint8_to_int64 u | U8, S128 -> uint64_to_int128 (uint8_to_uint64 u) | U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy | U16, U8 -> uint16_to_uint8 u | U16, U16 -> u | U16, U32 -> uint16_to_uint32 u | U16, U64 -> uint16_to_uint64 u | U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u) | U16, S8 -> uint16_to_int8 u | U16, S16 -> uint16_to_int16 u | U16, S32 -> uint16_to_int32 u | U16, S64 -> uint16_to_int64 u | U16, S128 -> uint64_to_int128 (uint16_to_uint64 u) | U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy | U32, U8 -> uint32_to_uint8 u | U32, U16 -> uint32_to_uint16 u | U32, U32 -> u | U32, U64 -> uint32_to_uint64 u | U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u) | U32, S8 -> uint32_to_int8 u | U32, S16 -> uint32_to_int16 u | U32, S32 -> uint32_to_int32 u | U32, S64 -> uint32_to_int64 u | U32, S128 -> uint64_to_int128 (uint32_to_uint64 u) | U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy | U64, U8 -> uint64_to_uint8 u | U64, U16 -> uint64_to_uint16 u | U64, U32 -> uint64_to_uint32 u | U64, U64 -> u | U64, U128 -> UInt128.uint64_to_uint128 u | U64, S8 -> uint64_to_int8 u | U64, S16 -> uint64_to_int16 u | U64, S32 -> uint64_to_int32 u | U64, S64 -> uint64_to_int64 u | U64, S128 -> uint64_to_int128 u | U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy | U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u) | U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u) | U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u) | U128, U64 -> UInt128.uint128_to_uint64 u | U128, U128 -> u | U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u) | U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u) | U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u) | U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u) | U128, S128 -> uint128_to_int128 u | S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy | S8, U8 -> int8_to_uint8 u | S8, U16 -> int8_to_uint16 u | S8, U32 -> int8_to_uint32 u | S8, U64 -> int8_to_uint64 u | S8, U128 -> int64_to_uint128 (int8_to_int64 u) | S8, S8 -> u | S8, S16 -> int8_to_int16 u | S8, S32 -> int8_to_int32 u | S8, S64 -> int8_to_int64 u | S8, S128 -> int64_to_int128 (int8_to_int64 u) | S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy | S16, U8 -> int16_to_uint8 u | S16, U16 -> int16_to_uint16 u | S16, U32 -> int16_to_uint32 u | S16, U64 -> int16_to_uint64 u | S16, U128 -> int64_to_uint128 (int16_to_int64 u) | S16, S8 -> int16_to_int8 u | S16, S16 -> u | S16, S32 -> int16_to_int32 u | S16, S64 -> int16_to_int64 u | S16, S128 -> int64_to_int128 (int16_to_int64 u) | S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy | S32, U8 -> int32_to_uint8 u | S32, U16 -> int32_to_uint16 u | S32, U32 -> int32_to_uint32 u | S32, U64 -> int32_to_uint64 u | S32, U128 -> int64_to_uint128 (int32_to_int64 u) | S32, S8 -> int32_to_int8 u | S32, S16 -> int32_to_int16 u | S32, S32 -> u | S32, S64 -> int32_to_int64 u | S32, S128 -> int64_to_int128 (int32_to_int64 u) | S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy | S64, U8 -> int64_to_uint8 u | S64, U16 -> int64_to_uint16 u | S64, U32 -> int64_to_uint32 u | S64, U64 -> int64_to_uint64 u | S64, U128 -> int64_to_uint128 u | S64, S8 -> int64_to_int8 u | S64, S16 -> int64_to_int16 u | S64, S32 -> int64_to_int32 u | S64, S64 -> u | S64, S128 -> int64_to_int128 u | S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy | S128, U8 -> uint64_to_uint8 (int128_to_uint64 u) | S128, U16 -> uint64_to_uint16 (int128_to_uint64 u) | S128, U32 -> uint64_to_uint32 (int128_to_uint64 u) | S128, U64 -> int128_to_uint64 u | S128, U128 -> int128_to_uint128 u | S128, S8 -> uint64_to_int8 (int128_to_uint64 u) | S128, S16 -> uint64_to_int16 (int128_to_uint64 u) | S128, S32 -> uint64_to_int32 (int128_to_uint64 u) | S128, S64 -> uint64_to_int64 (int128_to_uint64 u) | S128, S128 -> u #pop-options [@(strict_on_arguments [0])] let ones t l = match t with | U1 -> 0x1uy | U8 -> 0xFFuy | U16 -> 0xFFFFus | U32 -> 0xFFFFFFFFul | U64 -> 0xFFFFFFFFFFFFFFFFuL | U128 -> let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in let y = (UInt128.shift_left x 64ul) `UInt128.add` x in assert_norm (UInt128.v y == pow2 128 - 1); y | _ -> mk_int (-1) let zeros t l = mk_int 0 [@(strict_on_arguments [0])] let add_mod #t #l a b = match t with | U1 -> UInt8.rem (UInt8.add_mod a b) 2uy | U8 -> UInt8.add_mod a b | U16 -> UInt16.add_mod a b | U32 -> UInt32.add_mod a b | U64 -> UInt64.add_mod a b | U128 -> UInt128.add_mod a b let add_mod_lemma #t #l a b = () [@(strict_on_arguments [0])] let add #t #l a b = match t with | U1 -> UInt8.add a b | U8 -> UInt8.add a b | U16 -> UInt16.add a b | U32 -> UInt32.add a b | U64 -> UInt64.add a b | U128 -> UInt128.add a b | S8 -> Int8.add a b | S16 -> Int16.add a b | S32 -> Int32.add a b | S64 -> Int64.add a b | S128 -> Int128.add a b let add_lemma #t #l a b = () #push-options "--max_fuel 1" [@(strict_on_arguments [0])] let incr #t #l a = match t with | U1 -> UInt8.add a 1uy | U8 -> UInt8.add a 1uy | U16 -> UInt16.add a 1us | U32 -> UInt32.add a 1ul | U64 -> UInt64.add a 1uL | U128 -> UInt128.add a (UInt128.uint_to_t 1) | S8 -> Int8.add a 1y | S16 -> Int16.add a 1s | S32 -> Int32.add a 1l | S64 -> Int64.add a 1L | S128 -> Int128.add a (Int128.int_to_t 1) let incr_lemma #t #l a = () #pop-options [@(strict_on_arguments [0])] let mul_mod #t #l a b = match t with | U1 -> UInt8.mul_mod a b | U8 -> UInt8.mul_mod a b | U16 -> UInt16.mul_mod a b | U32 -> UInt32.mul_mod a b | U64 -> UInt64.mul_mod a b let mul_mod_lemma #t #l a b = () [@(strict_on_arguments [0])] let mul #t #l a b = match t with | U1 -> UInt8.mul a b | U8 -> UInt8.mul a b | U16 -> UInt16.mul a b | U32 -> UInt32.mul a b | U64 -> UInt64.mul a b | S8 -> Int8.mul a b | S16 -> Int16.mul a b | S32 -> Int32.mul a b | S64 -> Int64.mul a b let mul_lemma #t #l a b = () let mul64_wide a b = UInt128.mul_wide a b let mul64_wide_lemma a b = () let mul_s64_wide a b = Int128.mul_wide a b let mul_s64_wide_lemma a b = () [@(strict_on_arguments [0])] let sub_mod #t #l a b = match t with | U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy | U8 -> UInt8.sub_mod a b | U16 -> UInt16.sub_mod a b | U32 -> UInt32.sub_mod a b | U64 -> UInt64.sub_mod a b | U128 -> UInt128.sub_mod a b let sub_mod_lemma #t #l a b = () [@(strict_on_arguments [0])] let sub #t #l a b = match t with | U1 -> UInt8.sub a b | U8 -> UInt8.sub a b | U16 -> UInt16.sub a b | U32 -> UInt32.sub a b | U64 -> UInt64.sub a b | U128 -> UInt128.sub a b | S8 -> Int8.sub a b | S16 -> Int16.sub a b | S32 -> Int32.sub a b | S64 -> Int64.sub a b | S128 -> Int128.sub a b let sub_lemma #t #l a b = () #push-options "--max_fuel 1" [@(strict_on_arguments [0])] let decr #t #l a = match t with | U1 -> UInt8.sub a 1uy | U8 -> UInt8.sub a 1uy | U16 -> UInt16.sub a 1us | U32 -> UInt32.sub a 1ul | U64 -> UInt64.sub a 1uL | U128 -> UInt128.sub a (UInt128.uint_to_t 1) | S8 -> Int8.sub a 1y | S16 -> Int16.sub a 1s | S32 -> Int32.sub a 1l | S64 -> Int64.sub a 1L | S128 -> Int128.sub a (Int128.int_to_t 1) let decr_lemma #t #l a = () #pop-options [@(strict_on_arguments [0])] let logxor #t #l a b = match t with | U1 -> assert_norm (UInt8.logxor 0uy 0uy == 0uy); assert_norm (UInt8.logxor 0uy 1uy == 1uy); assert_norm (UInt8.logxor 1uy 0uy == 1uy); assert_norm (UInt8.logxor 1uy 1uy == 0uy); UInt8.logxor a b | U8 -> UInt8.logxor a b | U16 -> UInt16.logxor a b | U32 -> UInt32.logxor a b | U64 -> UInt64.logxor a b | U128 -> UInt128.logxor a b | S8 -> Int8.logxor a b | S16 -> Int16.logxor a b | S32 -> Int32.logxor a b | S64 -> Int64.logxor a b | S128 -> Int128.logxor a b #push-options "--max_fuel 1" val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma (v (a `logxor` (a `logxor` b)) == v b) let logxor_lemma_ #t #l a b = match t with | U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_associative #(bits t) (v a) (v a) (v b); UInt.logxor_self #(bits t) (v a); UInt.logxor_commutative #(bits t) 0 (v b); UInt.logxor_lemma_1 #(bits t) (v b) | S8 | S16 | S32 | S64 | S128 -> Int.logxor_associative #(bits t) (v a) (v a) (v b); Int.logxor_self #(bits t) (v a); Int.logxor_commutative #(bits t) 0 (v b); Int.logxor_lemma_1 #(bits t) (v b) let logxor_lemma #t #l a b = logxor_lemma_ #t a b; v_extensionality (logxor a (logxor a b)) b; begin match t with | U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b) | S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b) end; v_extensionality (logxor a (logxor b a)) b; begin match t with | U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a) | S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a) end; v_extensionality (logxor a (mk_int #t #l 0)) a let logxor_lemma1 #t #l a b = match v a, v b with | _, 0 -> UInt.logxor_lemma_1 #(bits t) (v a) | 0, _ -> UInt.logxor_commutative #(bits t) (v a) (v b); UInt.logxor_lemma_1 #(bits t) (v b) | 1, 1 -> v_extensionality a b; UInt.logxor_self #(bits t) (v a) let logxor_spec #t #l a b = match t with | U1 -> assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1); assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0); assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1); assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0) | _ -> () #pop-options [@(strict_on_arguments [0])] let logand #t #l a b = match t with | U1 -> assert_norm (UInt8.logand 0uy 0uy == 0uy); assert_norm (UInt8.logand 0uy 1uy == 0uy); assert_norm (UInt8.logand 1uy 0uy == 0uy); assert_norm (UInt8.logand 1uy 1uy == 1uy); UInt8.logand a b | U8 -> UInt8.logand a b | U16 -> UInt16.logand a b | U32 -> UInt32.logand a b | U64 -> UInt64.logand a b | U128 -> UInt128.logand a b | S8 -> Int8.logand a b | S16 -> Int16.logand a b | S32 -> Int32.logand a b | S64 -> Int64.logand a b | S128 -> Int128.logand a b let logand_zeros #t #l a = match t with | U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0) | U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a) | S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a) let logand_ones #t #l a = match t with | U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1) | U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a) | S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a) let logand_lemma #t #l a b = logand_zeros #t #l b; logand_ones #t #l b; match t with | U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0); assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1) | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b) | S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b) let logand_spec #t #l a b = match t with | U1 -> assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0); assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1); assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0); assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1) | _ -> () let logand_le #t #l a b = match t with | U1 -> assert_norm (UInt8.logand 0uy 0uy == 0uy); assert_norm (UInt8.logand 0uy 1uy == 0uy); assert_norm (UInt8.logand 1uy 0uy == 0uy); assert_norm (UInt8.logand 1uy 1uy == 1uy) | U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b)) | U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b)) | U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b)) | U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b)) | U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b)) let logand_mask #t #l a b m = match t with | U1 -> assert_norm (UInt8.logand 0uy 0uy == 0uy); assert_norm (UInt8.logand 0uy 1uy == 0uy); assert_norm (UInt8.logand 1uy 0uy == 0uy); assert_norm (UInt8.logand 1uy 1uy == 1uy) | U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m | U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m | U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m | U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m | U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m [@(strict_on_arguments [0])] let logor #t #l a b = match t with | U1 -> assert_norm (UInt8.logor 0uy 0uy == 0uy); assert_norm (UInt8.logor 0uy 1uy == 1uy); assert_norm (UInt8.logor 1uy 0uy == 1uy); assert_norm (UInt8.logor 1uy 1uy == 1uy); UInt8.logor a b | U8 -> UInt8.logor a b | U16 -> UInt16.logor a b | U32 -> UInt32.logor a b | U64 -> UInt64.logor a b | U128 -> UInt128.logor a b | S8 -> Int8.logor a b | S16 -> Int16.logor a b | S32 -> Int32.logor a b | S64 -> Int64.logor a b | S128 -> Int128.logor a b #push-options "--max_fuel 1" let logor_disjoint #t #l a b m = if m > 0 then begin UInt.logor_disjoint #(bits t) (v b) (v a) m; UInt.logor_commutative #(bits t) (v b) (v a) end else begin UInt.logor_commutative #(bits t) (v a) (v b); UInt.logor_lemma_1 #(bits t) (v b) end #pop-options let logor_zeros #t #l a = match t with |U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1) | U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a) | S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a) let logor_ones #t #l a = match t with |U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1) | U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a) | S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t)) let logor_lemma #t #l a b = logor_zeros #t #l b; logor_ones #t #l b; match t with | U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1); assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1) | U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b) | S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a)) let logor_spec #t #l a b = match t with | U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1); assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1); assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1); assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1) | _ -> () [@(strict_on_arguments [0])] let lognot #t #l a = match t with | U1 -> UInt8.rem (UInt8.lognot a) 2uy | U8 -> UInt8.lognot a | U16 -> UInt16.lognot a | U32 -> UInt32.lognot a | U64 -> UInt64.lognot a | U128 -> UInt128.lognot a | S8 -> Int8.lognot a | S16 -> Int16.lognot a | S32 -> Int32.lognot a | S64 -> Int64.lognot a | S128 -> Int128.lognot a let lognot_lemma #t #l a = match t with |U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0) | U8 | U16 | U32 | U64 | U128 -> FStar.UInt.lognot_lemma_1 #(bits t); UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t)) | S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t)); Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t)) let lognot_spec #t #l a = match t with | U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0); assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0) | _ -> () [@(strict_on_arguments [0])] let shift_right #t #l a b = match t with | U1 -> UInt8.shift_right a b | U8 -> UInt8.shift_right a b | U16 -> UInt16.shift_right a b | U32 -> UInt32.shift_right a b | U64 -> UInt64.shift_right a b | U128 -> UInt128.shift_right a b | S8 -> Int8.shift_arithmetic_right a b | S16 -> Int16.shift_arithmetic_right a b | S32 -> Int32.shift_arithmetic_right a b | S64 -> Int64.shift_arithmetic_right a b | S128 -> Int128.shift_arithmetic_right a b val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} -> Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s) let shift_right_value_aux_1 #n a s = pow2_le_compat s n; if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a #push-options "--z3rlimit 200" val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n -> Lemma (Int.shift_arithmetic_right #n a 1 = a / 2) let shift_right_value_aux_2 #n a = if a >= 0 then begin Int.sign_bit_positive a; UInt.shift_right_value_aux_3 #n a 1 end else begin Int.sign_bit_negative a; let a1 = Int.to_vec a in let au = Int.to_uint a in let sar = Int.shift_arithmetic_right #n a 1 in let sar1 = Int.to_vec sar in let sr = UInt.shift_right #n au 1 in let sr1 = UInt.to_vec sr in assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n)); assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n))); UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n); assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n)); UInt.slice_left_lemma a1 (n-1); assert (sar + pow2 n = pow2 (n-1) + (au / 2)); pow2_double_sum (n-1); assert (sar + pow2 (n-1) = (a + pow2 n) / 2); pow2_double_mult (n-1); lemma_div_plus a (pow2 (n-1)) 2; assert (sar = a / 2) end val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} -> Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s) (decreases s) let rec shift_right_value_aux_3 #n a s = if s = 1 then shift_right_value_aux_2 #n a else begin let a1 = Int.to_vec a in assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s) (BitVector.shift_arithmetic_right_vec #n (BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1)); assert (Int.shift_arithmetic_right #n a s = Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1); shift_right_value_aux_3 #n a (s-1); shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1)); assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2); pow2_double_mult (s-1); division_multiplication_lemma a (pow2 (s-1)) 2 end let shift_right_lemma #t #l a b = match t with | U1 | U8 | U16 | U32 | U64 | U128 -> () | S8 | S16 | S32 | S64 | S128 -> if v b = 0 then () else if v b >= bits t then shift_right_value_aux_1 #(bits t) (v a) (v b) else shift_right_value_aux_3 #(bits t) (v a) (v b) [@(strict_on_arguments [0])] let shift_left #t #l a b = match t with | U1 -> UInt8.shift_left a b | U8 -> UInt8.shift_left a b | U16 -> UInt16.shift_left a b | U32 -> UInt32.shift_left a b | U64 -> UInt64.shift_left a b | U128 -> UInt128.shift_left a b | S8 -> Int8.shift_left a b | S16 -> Int16.shift_left a b | S32 -> Int32.shift_left a b | S64 -> Int64.shift_left a b | S128 -> Int128.shift_left a b #push-options "--max_fuel 1" let shift_left_lemma #t #l a b = () let rotate_right #t #l a b = logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b)) let rotate_left #t #l a b = logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b)) [@(strict_on_arguments [0])] let ct_abs #t #l a = match t with | S8 -> Int8.ct_abs a | S16 -> Int16.ct_abs a | S32 -> Int32.ct_abs a | S64 -> Int64.ct_abs a #pop-options [@(strict_on_arguments [0])] let eq_mask #t a b = match t with | U1 -> lognot (logxor a b) | U8 -> UInt8.eq_mask a b | U16 -> UInt16.eq_mask a b | U32 -> UInt32.eq_mask a b | U64 -> UInt64.eq_mask a b | U128 -> UInt128.eq_mask a b | S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b)) | S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b)) | S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b)) | S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b)) val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma (if v a = v b then v (eq_mask a b) == ones_v t else v (eq_mask a b) == 0) let eq_mask_lemma_unsigned #t a b = match t with | U1 -> assert_norm ( logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\ logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\ lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1) | U8 | U16 | U32 | U64 | U128 -> () #push-options "--z3rlimit 200" val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma (if v a = v b then v (eq_mask a b) == ones_v t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.Cast.Full.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Int.fsti.checked", "FStar.BitVector.fst.checked" ], "interface_file": true, "source_file": "Lib.IntTypes.fst" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> FStar.Pervasives.Lemma (ensures ((match Lib.IntTypes.v a = Lib.IntTypes.v b with | true -> Lib.IntTypes.v (Lib.IntTypes.eq_mask a b) == Lib.IntTypes.ones_v t | _ -> Lib.IntTypes.v (Lib.IntTypes.eq_mask a b) == 0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.inttype", "Prims.l_and", "Prims.b2t", "Lib.IntTypes.signed", "Prims.l_not", "Lib.IntTypes.uu___is_S128", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "FStar.Math.Lemmas.modulo_lemma", "Prims.pow2", "Prims.bool", "Prims.op_Addition", "Prims.unit", "FStar.Math.Lemmas.modulo_addition_lemma", "FStar.Pervasives.assert_norm", "Prims.op_Equality", "Prims.int", "FStar.Mul.op_Star" ]
[]
false
false
true
false
false
let eq_mask_lemma_signed #t a b =
match t with | S8 -> assert_norm (pow2 8 = 2 * pow2 7); if 0 <= v a then modulo_lemma (v a) (pow2 8) else (modulo_addition_lemma (v a) 1 (pow2 8); modulo_lemma (v a + pow2 8) (pow2 8)) | S16 -> assert_norm (pow2 16 = 2 * pow2 15); if 0 <= v a then modulo_lemma (v a) (pow2 16) else (modulo_addition_lemma (v a) 1 (pow2 16); modulo_lemma (v a + pow2 16) (pow2 16)) | S32 -> if 0 <= v a then modulo_lemma (v a) (pow2 32) else (modulo_addition_lemma (v a) 1 (pow2 32); modulo_lemma (v a + pow2 32) (pow2 32)) | S64 -> if 0 <= v a then modulo_lemma (v a) (pow2 64) else (modulo_addition_lemma (v a) 1 (pow2 64); modulo_lemma (v a + pow2 64) (pow2 64))
false
Hacl.Poly1305_128.fst
Hacl.Poly1305_128.poly1305_update1
val poly1305_update1: poly1305_update1_st M128
val poly1305_update1: poly1305_update1_st M128
let poly1305_update1 = poly1305_update1 #M128
{ "file_name": "code/poly1305/Hacl.Poly1305_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 17, "start_col": 0, "start_line": 17 }
module Hacl.Poly1305_128 open FStar.HyperStack open FStar.HyperStack.All open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Fields open Hacl.Impl.Poly1305 open Hacl.Meta.Poly1305 friend Hacl.Meta.Poly1305 let poly1305_init = poly1305_init #M128
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Poly1305.fst.checked", "Hacl.Meta.Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Poly1305.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.Poly1305_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.Meta.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "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.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Poly1305.poly1305_update1_st Hacl.Impl.Poly1305.Fields.M128
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.poly1305_update1", "Hacl.Impl.Poly1305.Fields.M128" ]
[]
false
false
false
true
false
let poly1305_update1 =
poly1305_update1 #M128
false
IfcExample.fst
IfcExample.c1_ni
val c1_ni : unit -> Lemma (ni_com env c1 Low)
val c1_ni : unit -> Lemma (ni_com env c1 Low)
let c1_ni () = while_com env (AVar c) c1_6 (AVar c) Low
{ "file_name": "examples/rel/IfcExample.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 81, "start_col": 0, "start_line": 81 }
(* 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 IfcExample open Rel open While open IfcRules open FStar.Heap open FStar.ST (* (Warning) Top-level let-bindings must be total; this term may have effects *) assume val x : ref int assume val y : ref int assume val z : ref int assume val c : ref int let env (var: nat) = if var = addr_of x then Low else if var = addr_of y then Low else if var = addr_of c then Low else if var = addr_of z then High else High (* While c > 0{ x := y; y := y + 6; z := y + 7; x := z + 7; c := c - 1 } *) let c1_0 body = While (AVar c) body (AVar c) let c1_1 = Assign x (AVar y) let c1_2 = Assign y (AOp Plus (AVar x) (AInt 6)) let c1_3 = Assign z (AOp Plus (AVar y) (AInt 7)) let c1_4 = Assign x (AOp Plus (AVar z) (AInt 7)) let c1_5 = Assign c (AOp Minus (AVar c) (AInt 1)) let c1_6 = Seq c1_1 (Seq c1_2 (Seq c1_3 (Seq c1_4 c1_5))) let c1 = c1_0 c1_6 val c1_1_ni : unit -> Lemma (ni_com env c1_1 Low) let c1_1_ni () = () val c1_2_ni : unit -> Lemma (ni_com env c1_2 Low) let c1_2_ni () = () val c1_3_ni : unit -> Lemma (ni_com env c1_3 Low) let c1_3_ni () = () (* c1_4 cannot be shown to be non-interferent by typing since it contains an explicit flow from z (High) to x (Low) However, the sequence of c1_3 and c1_4 is fine, since in c1_3 we overwrite z with the low value (y+7). We can hence prove non-interference by relying on SMT. *) val c1_3_4_ni : unit -> Lemma (ni_com env (Seq c1_3 c1_4) Low) let c1_3_4_ni () = () (* The SMT solver cannot show noninterference of the loop without further guidance, so we rely on the While-rule instead *)
{ "checked_file": "/", "dependencies": [ "While.fst.checked", "Rel.fst.checked", "prims.fst.checked", "IfcRules.fst.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "IfcExample.fst" }
[ { "abbrev": false, "full_module": "FStar.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Heap", "short_module": null }, { "abbrev": false, "full_module": "IfcRules", "short_module": null }, { "abbrev": false, "full_module": "While", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures IfcRules.ni_com IfcExample.env IfcExample.c1 IfcRules.Low)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "IfcRules.while_com", "IfcExample.env", "While.AVar", "IfcExample.c", "IfcExample.c1_6", "IfcRules.Low" ]
[]
true
false
true
false
false
let c1_ni () =
while_com env (AVar c) c1_6 (AVar c) Low
false
Hacl.Poly1305_128.fst
Hacl.Poly1305_128.poly1305_init
val poly1305_init: poly1305_init_st M128
val poly1305_init: poly1305_init_st M128
let poly1305_init = poly1305_init #M128
{ "file_name": "code/poly1305/Hacl.Poly1305_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 15, "start_col": 0, "start_line": 15 }
module Hacl.Poly1305_128 open FStar.HyperStack open FStar.HyperStack.All open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Fields open Hacl.Impl.Poly1305 open Hacl.Meta.Poly1305 friend Hacl.Meta.Poly1305
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Poly1305.fst.checked", "Hacl.Meta.Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Poly1305.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.Poly1305_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.Meta.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "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.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Poly1305.poly1305_init_st Hacl.Impl.Poly1305.Fields.M128
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.poly1305_init", "Hacl.Impl.Poly1305.Fields.M128" ]
[]
false
false
false
true
false
let poly1305_init =
poly1305_init #M128
false
Hacl.Impl.P256.Constants.fst
Hacl.Impl.P256.Constants.make_order
val make_order: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.order)
val make_order: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.order)
let make_order n = // 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551 [@inline_let] let n0 = u64 0xf3b9cac2fc632551 in [@inline_let] let n1 = u64 0xbce6faada7179e84 in [@inline_let] let n2 = u64 0xffffffffffffffff in [@inline_let] let n3 = u64 0xffffffff00000000 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.order); bn_make_u64_4 n n0 n1 n2 n3
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.Constants.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 47, "start_col": 0, "start_line": 40 }
module Hacl.Impl.P256.Constants 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 module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val make_prime: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.prime) [@CInline] let make_prime n = // 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff [@inline_let] let n0 = u64 0xffffffffffffffff in [@inline_let] let n1 = u64 0xffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xffffffff00000001 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.prime); bn_make_u64_4 n n0 n1 n2 n3 val make_order: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.order)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.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": false, "source_file": "Hacl.Impl.P256.Constants.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "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": 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
n: Hacl.Impl.P256.Bignum.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.P256.Bignum.felem", "Hacl.Impl.P256.Bignum.bn_make_u64_4", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Mul.op_Star", "Prims.pow2", "Spec.P256.PointOps.order", "Lib.IntTypes.int_t", "Prims.eq2", "Lib.IntTypes.range", "Lib.IntTypes.u64" ]
[]
false
true
false
false
false
let make_order n =
[@@ inline_let ]let n0 = u64 0xf3b9cac2fc632551 in [@@ inline_let ]let n1 = u64 0xbce6faada7179e84 in [@@ inline_let ]let n2 = u64 0xffffffffffffffff in [@@ inline_let ]let n3 = u64 0xffffffff00000000 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.order); bn_make_u64_4 n n0 n1 n2 n3
false
Lib.Sequence.fst
Lib.Sequence.index_generate_blocks
val index_generate_blocks: #t:Type0 -> len:size_pos -> max:nat -> n:pos{n <= max} -> f:(i:nat{i < max} -> unit -> unit & s:seq t{length s == len}) -> i:nat{i < n * len} -> Lemma (Math.Lemmas.lemma_mult_le_right len n max; div_mul_lt len i max; let a_spec (i:nat{i <= max}) = unit in let _,s1 = generate_blocks len max n a_spec f () in let _,s2 = f (i / len) () in Seq.index s1 i == Seq.index s2 (i % len))
val index_generate_blocks: #t:Type0 -> len:size_pos -> max:nat -> n:pos{n <= max} -> f:(i:nat{i < max} -> unit -> unit & s:seq t{length s == len}) -> i:nat{i < n * len} -> Lemma (Math.Lemmas.lemma_mult_le_right len n max; div_mul_lt len i max; let a_spec (i:nat{i <= max}) = unit in let _,s1 = generate_blocks len max n a_spec f () in let _,s2 = f (i / len) () in Seq.index s1 i == Seq.index s2 (i % len))
let rec index_generate_blocks #t len max n f i = assert (0 < n); let a_spec (i:nat{i <= max}) = unit in let _,s = generate_blocks #t len max (n-1) a_spec f () in let _,s' = f (n-1) () in let _,s1 = generate_blocks #t len max n a_spec f () in unfold_generate_blocks #t len max a_spec f () (n-1); Seq.Properties.lemma_split s1 (n * len - len); Seq.Properties.lemma_split (Seq.append s s') (n * len - len); Seq.lemma_eq_intro s1 (Seq.append s s'); if i < (n-1) * len then begin Seq.lemma_index_app1 s s' i; index_generate_blocks len max (n-1) f i end else begin Seq.lemma_index_app2 s s' i; mod_prop len (n-1) i end
{ "file_name": "lib/Lib.Sequence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 7, "end_line": 367, "start_col": 0, "start_line": 348 }
module Lib.Sequence open FStar.Mul open Lib.IntTypes open Lib.LoopCombinators #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'" let index #a #len s n = Seq.index s n let create #a len init = Seq.create #a len init let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1 let to_list #a s = Seq.seq_to_list s let of_list #a l = Seq.seq_of_list #a l let of_list_index #a l i = Seq.lemma_seq_of_list_index #a l i let equal #a #len s1 s2 = forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i let eq_intro #a #len s1 s2 = assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)} index s1 i == index s2 i); Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2) let eq_elim #a #len s1 s2 = assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)} index s1 i == index s2 i); Seq.lemma_eq_elim #a s1 s2 let upd #a #len s n x = Seq.upd #a s n x let member #a #len x l = Seq.count x l > 0 let sub #a #len s start n = Seq.slice #a s start (start + n) let update_sub #a #len s start n x = let o = Seq.append (Seq.append (Seq.slice s 0 start) x) (Seq.slice s (start + n) (length s)) in Seq.lemma_eq_intro (Seq.slice o start (start + n)) x; o let lemma_update_sub #a #len dst start n src res = let res1 = update_sub dst start n src in Seq.lemma_split (sub res 0 (start + n)) start; Seq.lemma_split (sub res1 0 (start + n)) start; Seq.lemma_split res (start + n); Seq.lemma_split res1 (start + n); Seq.lemma_eq_intro res (update_sub dst start n src) let lemma_concat2 #a len0 s0 len1 s1 s = Seq.Properties.lemma_split s len0; Seq.Properties.lemma_split (concat s0 s1) len0; Seq.lemma_eq_intro s (concat s0 s1) let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s = let s' = concat (concat s0 s1) s2 in Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0; Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0; Seq.Properties.lemma_split s (len0 + len1); Seq.Properties.lemma_split s' (len0 + len1); Seq.lemma_eq_intro s (concat (concat s0 s1) s2) let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) = lseq a k let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) (s:createi_a a len init k) = forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len}) (si:createi_a a len init i) : r:createi_a a len init (i + 1) {createi_pred a len init i si ==> createi_pred a len init (i + 1) r} = assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j)); Seq.snoc si (init i) #push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'" let createi #a len init_f = repeat_gen_inductive len (createi_a a len init_f) (createi_pred a len init_f) (createi_step a len init_f) (of_list []) #pop-options inline_for_extraction let mapi_inner (#a:Type) (#b:Type) (#len:size_nat) (f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) = f i s.[i] let mapi #a #b #len f s = createi #b len (mapi_inner #a #b #len f s) inline_for_extraction let map_inner (#a:Type) (#b:Type) (#len:size_nat) (f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) = f s.[i] let map #a #b #len f s = createi #b len (map_inner #a #b #len f s) let map2i #a #b #c #len f s1 s2 = createi #c len (fun i -> f i s1.[i] s2.[i]) inline_for_extraction let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat) (f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) = f s1.[i] s2.[i] let map2 #a #b #c #len f s1 s2 = createi #c len (map2_inner #a #b #c #len f s1 s2) let for_all #a #len f x = Seq.for_all f x let for_all2 #a #b #len f x y = let r = map2 (fun xi yi -> f xi yi) x y in Seq.for_all (fun bi -> bi = true) r (** Selecting a subset of an unbounded Sequence *) val seq_sub: #a:Type -> s1:seq a -> start:nat -> n:nat{start + n <= length s1} -> s2:seq a{length s2 == n /\ (forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))} let seq_sub #a s start n = Seq.slice #a s start (start + n) (** Updating a subset of an unbounded Sequence with another Sequence *) val seq_update_sub: #a:Type -> i:seq a -> start:nat -> n:nat{start + n <= length i} -> x:seq a{length x == n} -> o:seq a{length o == length i /\ seq_sub o start n == x /\ (forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}). {:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)} let seq_update_sub #a s start n x = let o = Seq.append (Seq.append (Seq.slice s 0 start) x) (Seq.slice s (start + n) (length s)) in Seq.lemma_eq_intro (Seq.slice o start (start + n)) x; o val repeati_blocks_f: #a:Type0 -> #b:Type0 -> blocksize:size_nat{blocksize > 0} -> inp:seq a -> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b) -> nb:nat{nb == length inp / blocksize} -> i:nat{i < nb} -> acc:b -> b let repeati_blocks_f #a #b bs inp f nb i acc = assert ((i+1) * bs <= nb * bs); let block = seq_sub inp (i * bs) bs in f i block acc let repeati_blocks #a #b bs inp f g init = let len = length inp in let nb = len / bs in let rem = len % bs in let acc = repeati nb (repeati_blocks_f bs inp f nb) init in let last = seq_sub inp (nb * bs) rem in g nb rem last acc let repeat_blocks #a #b #c bs inp f l init = let len = length inp in let nb = len / bs in let rem = len % bs in let acc = repeati nb (repeat_blocks_f bs inp f nb) init in let last = seq_sub inp (nb * bs) rem in l rem last acc let lemma_repeat_blocks #a #b #c bs inp f l init = () let repeat_blocks_multi #a #b bs inp f init = let len = length inp in let nb = len / bs in repeati nb (repeat_blocks_f bs inp f nb) init let lemma_repeat_blocks_multi #a #b bs inp f init = () let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen} let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) = let acc, o = acc in let acc', block = f i acc in let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in acc', o' let generate_blocks #t len max n a f acc0 = let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0 let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs} let generate_blocks_simple_f (#a:Type) (bs:size_nat{bs > 0}) (max:nat) (f:(i:nat{i < max} -> lseq a bs)) (i:nat{i < max}) (acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1) = Seq.append acc (f i) let generate_blocks_simple #a bs max nb f = repeat_gen nb (generate_blocks_simple_a a bs max) (generate_blocks_simple_f #a bs max f) Seq.empty #restart-solver let div_interval b n i = Math.Lemmas.lemma_div_le (n * b) i b; Math.Lemmas.cancel_mul_div n b let mod_interval_lt b n i j = div_interval b n i; div_interval b n j let div_mul_lt b a n = () let mod_div_lt b i j = mod_interval_lt b (j / b) i j let div_mul_l a b c d = calc (==) { a / (c * d); == { } a / (d * c); == { Math.Lemmas.division_multiplication_lemma a d c } (a / d) / c; == { } (b / d) / c; == { Math.Lemmas.division_multiplication_lemma b d c } b / (d * c); == { } b / (c * d); } let map_blocks_multi #a bs max nb inp f = repeat_gen nb (map_blocks_a a bs max) (map_blocks_f #a bs max inp f) Seq.empty let lemma_map_blocks_multi #a bs max nb inp f = () private val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} -> Lemma (b - a * n == b % n) let mod_prop n a b = Math.Lemmas.modulo_lemma (b - a * n) n; Math.Lemmas.lemma_mod_sub b n a #push-options "--z3rlimit 200" let rec index_map_blocks_multi #a bs max n inp f i = let map_blocks_a = map_blocks_a a bs max in let map_blocks_f = map_blocks_f #a bs max inp f in let acc0 = Seq.empty #a in let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1); let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in //assert (s1 == map_blocks_f (n-1) s); let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in //assert (s1 == Seq.append s s'); if i < (n-1)*bs then begin Seq.lemma_index_app1 s s' i; index_map_blocks_multi #a bs max (n-1) inp f i end else begin Seq.lemma_index_app2 s s' i; mod_prop bs (n-1) i end let map_blocks #a blocksize inp f g = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in let bs = map_blocks_multi #a blocksize nb nb blocks f in if (rem > 0) then Seq.append bs (g nb rem last) else bs let lemma_map_blocks #a blocksize inp f g = () let index_map_blocks #a bs inp f g i = let len = length inp in let nb = len / bs in let rem = len % bs in let blocks = Seq.slice inp 0 (nb * bs) in if rem > 0 then begin let s1 = map_blocks_multi #a bs nb nb blocks f in let last = Seq.slice inp (nb * bs) len in calc (==) { length last; == { Seq.lemma_len_slice inp (nb * bs) len } len - nb * bs; == {mod_prop bs nb len} len % bs; == { } rem; }; let s2 = g nb rem last in assert (Seq.equal (map_blocks bs inp f g) (Seq.append s1 s2)); if i < nb * bs then begin div_mul_lt bs i nb; Seq.lemma_index_app1 s1 s2 i; index_map_blocks_multi bs nb nb blocks f i end else begin Seq.lemma_index_app2 s1 s2 i; mod_prop bs nb i end end else index_map_blocks_multi #a bs nb nb blocks f i let eq_generate_blocks0 #t len n a f acc0 = let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in assert (generate_blocks #t len n 0 a f acc0 == repeat_gen 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0); eq_repeat_gen0 0 (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 let unfold_generate_blocks #t len n a f acc0 i = let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in assert (generate_blocks #t len n (i+1) a f acc0 == repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0); unfold_repeat_gen (i+1) (generate_blocks_a t len n a) (generate_blocks_inner t len n a f) a0 i
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.Sequence.fst" }
[ { "abbrev": false, "full_module": "Lib.LoopCombinators", "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": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_pos -> max: Prims.nat -> n: Prims.pos{n <= max} -> f: (i: Prims.nat{i < max} -> _: Prims.unit -> Prims.unit * s: Lib.Sequence.seq t {Lib.Sequence.length s == len}) -> i: Prims.nat{i < n * len} -> FStar.Pervasives.Lemma (ensures (FStar.Math.Lemmas.lemma_mult_le_right len n max; Lib.Sequence.div_mul_lt len i max; let a_spec i = Prims.unit in let _ = Lib.Sequence.generate_blocks len max n a_spec f () in (let FStar.Pervasives.Native.Mktuple2 #_ #_ _ s1 = _ in let _ = f (i / len) () in (let FStar.Pervasives.Native.Mktuple2 #_ #_ _ s2 = _ in FStar.Seq.Base.index s1 i == FStar.Seq.Base.index s2 (i % len)) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.unit", "FStar.Pervasives.Native.tuple2", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "Prims.l_and", "Prims.op_GreaterThan", "Lib.IntTypes.max_size_t", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Lib.Sequence.index_generate_blocks", "FStar.Seq.Base.lemma_index_app1", "Prims.bool", "Lib.Sequence.mod_prop", "FStar.Seq.Base.lemma_index_app2", "FStar.Seq.Base.lemma_eq_intro", "FStar.Seq.Base.append", "FStar.Seq.Properties.lemma_split", "Lib.Sequence.unfold_generate_blocks", "Prims.op_Multiply", "Lib.Sequence.generate_blocks", "Prims.pow2", "Prims.eqtype", "Prims._assert" ]
[ "recursion" ]
false
false
true
false
false
let rec index_generate_blocks #t len max n f i =
assert (0 < n); let a_spec (i: nat{i <= max}) = unit in let _, s = generate_blocks #t len max (n - 1) a_spec f () in let _, s' = f (n - 1) () in let _, s1 = generate_blocks #t len max n a_spec f () in unfold_generate_blocks #t len max a_spec f () (n - 1); Seq.Properties.lemma_split s1 (n * len - len); Seq.Properties.lemma_split (Seq.append s s') (n * len - len); Seq.lemma_eq_intro s1 (Seq.append s s'); if i < (n - 1) * len then (Seq.lemma_index_app1 s s' i; index_generate_blocks len max (n - 1) f i) else (Seq.lemma_index_app2 s s' i; mod_prop len (n - 1) i)
false
Hacl.Poly1305_128.fst
Hacl.Poly1305_128.poly1305_update
val poly1305_update: poly1305_update_st M128
val poly1305_update: poly1305_update_st M128
let poly1305_update = poly1305_update #M128
{ "file_name": "code/poly1305/Hacl.Poly1305_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 19, "start_col": 0, "start_line": 19 }
module Hacl.Poly1305_128 open FStar.HyperStack open FStar.HyperStack.All open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Fields open Hacl.Impl.Poly1305 open Hacl.Meta.Poly1305 friend Hacl.Meta.Poly1305 let poly1305_init = poly1305_init #M128 let poly1305_update1 = poly1305_update1 #M128
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Poly1305.fst.checked", "Hacl.Meta.Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Poly1305.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.Poly1305_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.Meta.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "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.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Poly1305.poly1305_update_st Hacl.Impl.Poly1305.Fields.M128
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.poly1305_update", "Hacl.Impl.Poly1305.Fields.M128" ]
[]
false
false
false
true
false
let poly1305_update =
poly1305_update #M128
false
Hacl.Poly1305_128.fst
Hacl.Poly1305_128.poly1305_finish
val poly1305_finish: poly1305_finish_st M128
val poly1305_finish: poly1305_finish_st M128
let poly1305_finish = poly1305_finish #M128
{ "file_name": "code/poly1305/Hacl.Poly1305_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 21, "start_col": 0, "start_line": 21 }
module Hacl.Poly1305_128 open FStar.HyperStack open FStar.HyperStack.All open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Poly1305.Fields open Hacl.Impl.Poly1305 open Hacl.Meta.Poly1305 friend Hacl.Meta.Poly1305 let poly1305_init = poly1305_init #M128 let poly1305_update1 = poly1305_update1 #M128 let poly1305_update = poly1305_update #M128
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Poly1305.fst.checked", "Hacl.Meta.Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Poly1305.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.Poly1305_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.Meta.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "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.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Poly1305.poly1305_finish_st Hacl.Impl.Poly1305.Fields.M128
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Poly1305.poly1305_finish", "Hacl.Impl.Poly1305.Fields.M128" ]
[]
false
false
false
true
false
let poly1305_finish =
poly1305_finish #M128
false
Hacl.Impl.P256.Constants.fst
Hacl.Impl.P256.Constants.make_prime
val make_prime: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.prime)
val make_prime: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.prime)
let make_prime n = // 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff [@inline_let] let n0 = u64 0xffffffffffffffff in [@inline_let] let n1 = u64 0xffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xffffffff00000001 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.prime); bn_make_u64_4 n n0 n1 n2 n3
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.Constants.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 31, "start_col": 0, "start_line": 24 }
module Hacl.Impl.P256.Constants 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 module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val make_prime: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.prime)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.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": false, "source_file": "Hacl.Impl.P256.Constants.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "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": 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
n: Hacl.Impl.P256.Bignum.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.P256.Bignum.felem", "Hacl.Impl.P256.Bignum.bn_make_u64_4", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Mul.op_Star", "Prims.pow2", "Spec.P256.PointOps.prime", "Lib.IntTypes.int_t", "Prims.eq2", "Lib.IntTypes.range", "Lib.IntTypes.u64" ]
[]
false
true
false
false
false
let make_prime n =
[@@ inline_let ]let n0 = u64 0xffffffffffffffff in [@@ inline_let ]let n1 = u64 0xffffffff in [@@ inline_let ]let n2 = u64 0x0 in [@@ inline_let ]let n3 = u64 0xffffffff00000001 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.prime); bn_make_u64_4 n n0 n1 n2 n3
false
Hacl.Impl.P256.Constants.fst
Hacl.Impl.P256.Constants.make_g_x
val make_g_x: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n < S.prime /\ SM.from_mont (as_nat h1 n) == S.g_x)
val make_g_x: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n < S.prime /\ SM.from_mont (as_nat h1 n) == S.g_x)
let make_g_x n = // g_x = 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296 // mont_g_x = 0x18905f76a53755c679fb732b7762251075ba95fc5fedb60179e730d418a9143c [@inline_let] let n0 = u64 0x79e730d418a9143c in [@inline_let] let n1 = u64 0x75ba95fc5fedb601 in [@inline_let] let n2 = u64 0x79fb732b77622510 in [@inline_let] let n3 = u64 0x18905f76a53755c6 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.g_x == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.g_x; bn_make_u64_4 n n0 n1 n2 n3
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.Constants.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 107, "start_col": 0, "start_line": 97 }
module Hacl.Impl.P256.Constants 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 module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val make_prime: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.prime) [@CInline] let make_prime n = // 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff [@inline_let] let n0 = u64 0xffffffffffffffff in [@inline_let] let n1 = u64 0xffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xffffffff00000001 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.prime); bn_make_u64_4 n n0 n1 n2 n3 val make_order: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.order) [@CInline] let make_order n = // 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551 [@inline_let] let n0 = u64 0xf3b9cac2fc632551 in [@inline_let] let n1 = u64 0xbce6faada7179e84 in [@inline_let] let n2 = u64 0xffffffffffffffff in [@inline_let] let n3 = u64 0xffffffff00000000 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.order); bn_make_u64_4 n n0 n1 n2 n3 val make_a_coeff: a:felem -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_nat h1 a < S.prime /\ SM.from_mont (as_nat h1 a) == S.a_coeff) [@CInline] let make_a_coeff a = // a_coeff = 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc // a_coeff_mont = 0xfffffffc00000004000000000000000000000003fffffffffffffffffffffffc [@inline_let] let n0 = u64 0xfffffffffffffffc in [@inline_let] let n1 = u64 0x3ffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xfffffffc00000004 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.a_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.a_coeff; bn_make_u64_4 a n0 n1 n2 n3 val make_b_coeff: b:felem -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_nat h1 b < S.prime /\ SM.from_mont (as_nat h1 b) == S.b_coeff) [@CInline] let make_b_coeff b = // b_coeff = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b // b_coeff_mont = 0xdc30061d04874834e5a220abf7212ed6acf005cd78843090d89cdf6229c4bddf [@inline_let] let n0 = u64 0xd89cdf6229c4bddf in [@inline_let] let n1 = u64 0xacf005cd78843090 in [@inline_let] let n2 = u64 0xe5a220abf7212ed6 in [@inline_let] let n3 = u64 0xdc30061d04874834 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.b_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.b_coeff; bn_make_u64_4 b n0 n1 n2 n3 val make_g_x: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n < S.prime /\ SM.from_mont (as_nat h1 n) == S.g_x)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.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": false, "source_file": "Hacl.Impl.P256.Constants.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "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": 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
n: Hacl.Impl.P256.Bignum.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.P256.Bignum.felem", "Hacl.Impl.P256.Bignum.bn_make_u64_4", "Prims.unit", "Hacl.Spec.P256.Montgomery.lemma_to_from_mont_id", "Spec.P256.PointOps.g_x", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Hacl.Spec.P256.Montgomery.to_mont", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Mul.op_Star", "Prims.pow2", "Prims.b2t", "Prims.op_LessThan", "Spec.P256.PointOps.prime", "Lib.IntTypes.int_t", "Lib.IntTypes.range", "Lib.IntTypes.u64" ]
[]
false
true
false
false
false
let make_g_x n =
[@@ inline_let ]let n0 = u64 0x79e730d418a9143c in [@@ inline_let ]let n1 = u64 0x75ba95fc5fedb601 in [@@ inline_let ]let n2 = u64 0x79fb732b77622510 in [@@ inline_let ]let n3 = u64 0x18905f76a53755c6 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.g_x == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.g_x; bn_make_u64_4 n n0 n1 n2 n3
false
Hacl.Impl.P256.Constants.fst
Hacl.Impl.P256.Constants.make_fmont_R2
val make_fmont_R2: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == SM.fmont_R * SM.fmont_R % S.prime)
val make_fmont_R2: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == SM.fmont_R * SM.fmont_R % S.prime)
let make_fmont_R2 n = // 0x4fffffffdfffffffffffffffefffffffbffffffff0000000000000003 [@inline_let] let n0 = u64 0x3 in [@inline_let] let n1 = u64 0xfffffffbffffffff in [@inline_let] let n2 = u64 0xfffffffffffffffe in [@inline_let] let n3 = u64 0x4fffffffd in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 == SM.fmont_R * SM.fmont_R % S.prime); bn_make_u64_4 n n0 n1 n2 n3
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.Constants.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 144, "start_col": 0, "start_line": 136 }
module Hacl.Impl.P256.Constants 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 module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val make_prime: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.prime) [@CInline] let make_prime n = // 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff [@inline_let] let n0 = u64 0xffffffffffffffff in [@inline_let] let n1 = u64 0xffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xffffffff00000001 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.prime); bn_make_u64_4 n n0 n1 n2 n3 val make_order: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.order) [@CInline] let make_order n = // 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551 [@inline_let] let n0 = u64 0xf3b9cac2fc632551 in [@inline_let] let n1 = u64 0xbce6faada7179e84 in [@inline_let] let n2 = u64 0xffffffffffffffff in [@inline_let] let n3 = u64 0xffffffff00000000 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.order); bn_make_u64_4 n n0 n1 n2 n3 val make_a_coeff: a:felem -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_nat h1 a < S.prime /\ SM.from_mont (as_nat h1 a) == S.a_coeff) [@CInline] let make_a_coeff a = // a_coeff = 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc // a_coeff_mont = 0xfffffffc00000004000000000000000000000003fffffffffffffffffffffffc [@inline_let] let n0 = u64 0xfffffffffffffffc in [@inline_let] let n1 = u64 0x3ffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xfffffffc00000004 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.a_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.a_coeff; bn_make_u64_4 a n0 n1 n2 n3 val make_b_coeff: b:felem -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_nat h1 b < S.prime /\ SM.from_mont (as_nat h1 b) == S.b_coeff) [@CInline] let make_b_coeff b = // b_coeff = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b // b_coeff_mont = 0xdc30061d04874834e5a220abf7212ed6acf005cd78843090d89cdf6229c4bddf [@inline_let] let n0 = u64 0xd89cdf6229c4bddf in [@inline_let] let n1 = u64 0xacf005cd78843090 in [@inline_let] let n2 = u64 0xe5a220abf7212ed6 in [@inline_let] let n3 = u64 0xdc30061d04874834 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.b_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.b_coeff; bn_make_u64_4 b n0 n1 n2 n3 val make_g_x: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n < S.prime /\ SM.from_mont (as_nat h1 n) == S.g_x) [@CInline] let make_g_x n = // g_x = 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296 // mont_g_x = 0x18905f76a53755c679fb732b7762251075ba95fc5fedb60179e730d418a9143c [@inline_let] let n0 = u64 0x79e730d418a9143c in [@inline_let] let n1 = u64 0x75ba95fc5fedb601 in [@inline_let] let n2 = u64 0x79fb732b77622510 in [@inline_let] let n3 = u64 0x18905f76a53755c6 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.g_x == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.g_x; bn_make_u64_4 n n0 n1 n2 n3 val make_g_y: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n < S.prime /\ SM.from_mont (as_nat h1 n) == S.g_y) [@CInline] let make_g_y n = // g_y = 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5 // mont_g_x = 0x8571ff1825885d85d2e88688dd21f3258b4ab8e4ba19e45cddf25357ce95560a [@inline_let] let n0 = u64 0xddf25357ce95560a in [@inline_let] let n1 = u64 0x8b4ab8e4ba19e45c in [@inline_let] let n2 = u64 0xd2e88688dd21f325 in [@inline_let] let n3 = u64 0x8571ff1825885d85 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.g_y == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.g_y; bn_make_u64_4 n n0 n1 n2 n3 val make_fmont_R2: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == SM.fmont_R * SM.fmont_R % S.prime)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.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": false, "source_file": "Hacl.Impl.P256.Constants.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "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": 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
n: Hacl.Impl.P256.Bignum.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.P256.Bignum.felem", "Hacl.Impl.P256.Bignum.bn_make_u64_4", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Mul.op_Star", "Prims.pow2", "Prims.op_Modulus", "Hacl.Spec.P256.Montgomery.fmont_R", "Spec.P256.PointOps.prime", "Lib.IntTypes.int_t", "Lib.IntTypes.range", "Lib.IntTypes.u64" ]
[]
false
true
false
false
false
let make_fmont_R2 n =
[@@ inline_let ]let n0 = u64 0x3 in [@@ inline_let ]let n1 = u64 0xfffffffbffffffff in [@@ inline_let ]let n2 = u64 0xfffffffffffffffe in [@@ inline_let ]let n3 = u64 0x4fffffffd in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 == SM.fmont_R * SM.fmont_R % S.prime); bn_make_u64_4 n n0 n1 n2 n3
false
Hacl.Impl.P256.Constants.fst
Hacl.Impl.P256.Constants.make_g_y
val make_g_y: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n < S.prime /\ SM.from_mont (as_nat h1 n) == S.g_y)
val make_g_y: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n < S.prime /\ SM.from_mont (as_nat h1 n) == S.g_y)
let make_g_y n = // g_y = 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5 // mont_g_x = 0x8571ff1825885d85d2e88688dd21f3258b4ab8e4ba19e45cddf25357ce95560a [@inline_let] let n0 = u64 0xddf25357ce95560a in [@inline_let] let n1 = u64 0x8b4ab8e4ba19e45c in [@inline_let] let n2 = u64 0xd2e88688dd21f325 in [@inline_let] let n3 = u64 0x8571ff1825885d85 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.g_y == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.g_y; bn_make_u64_4 n n0 n1 n2 n3
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.Constants.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 127, "start_col": 0, "start_line": 117 }
module Hacl.Impl.P256.Constants 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 module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val make_prime: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.prime) [@CInline] let make_prime n = // 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff [@inline_let] let n0 = u64 0xffffffffffffffff in [@inline_let] let n1 = u64 0xffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xffffffff00000001 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.prime); bn_make_u64_4 n n0 n1 n2 n3 val make_order: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.order) [@CInline] let make_order n = // 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551 [@inline_let] let n0 = u64 0xf3b9cac2fc632551 in [@inline_let] let n1 = u64 0xbce6faada7179e84 in [@inline_let] let n2 = u64 0xffffffffffffffff in [@inline_let] let n3 = u64 0xffffffff00000000 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.order); bn_make_u64_4 n n0 n1 n2 n3 val make_a_coeff: a:felem -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_nat h1 a < S.prime /\ SM.from_mont (as_nat h1 a) == S.a_coeff) [@CInline] let make_a_coeff a = // a_coeff = 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc // a_coeff_mont = 0xfffffffc00000004000000000000000000000003fffffffffffffffffffffffc [@inline_let] let n0 = u64 0xfffffffffffffffc in [@inline_let] let n1 = u64 0x3ffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xfffffffc00000004 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.a_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.a_coeff; bn_make_u64_4 a n0 n1 n2 n3 val make_b_coeff: b:felem -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_nat h1 b < S.prime /\ SM.from_mont (as_nat h1 b) == S.b_coeff) [@CInline] let make_b_coeff b = // b_coeff = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b // b_coeff_mont = 0xdc30061d04874834e5a220abf7212ed6acf005cd78843090d89cdf6229c4bddf [@inline_let] let n0 = u64 0xd89cdf6229c4bddf in [@inline_let] let n1 = u64 0xacf005cd78843090 in [@inline_let] let n2 = u64 0xe5a220abf7212ed6 in [@inline_let] let n3 = u64 0xdc30061d04874834 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.b_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.b_coeff; bn_make_u64_4 b n0 n1 n2 n3 val make_g_x: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n < S.prime /\ SM.from_mont (as_nat h1 n) == S.g_x) [@CInline] let make_g_x n = // g_x = 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296 // mont_g_x = 0x18905f76a53755c679fb732b7762251075ba95fc5fedb60179e730d418a9143c [@inline_let] let n0 = u64 0x79e730d418a9143c in [@inline_let] let n1 = u64 0x75ba95fc5fedb601 in [@inline_let] let n2 = u64 0x79fb732b77622510 in [@inline_let] let n3 = u64 0x18905f76a53755c6 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.g_x == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.g_x; bn_make_u64_4 n n0 n1 n2 n3 val make_g_y: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n < S.prime /\ SM.from_mont (as_nat h1 n) == S.g_y)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.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": false, "source_file": "Hacl.Impl.P256.Constants.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "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": 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
n: Hacl.Impl.P256.Bignum.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.P256.Bignum.felem", "Hacl.Impl.P256.Bignum.bn_make_u64_4", "Prims.unit", "Hacl.Spec.P256.Montgomery.lemma_to_from_mont_id", "Spec.P256.PointOps.g_y", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Hacl.Spec.P256.Montgomery.to_mont", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Mul.op_Star", "Prims.pow2", "Prims.b2t", "Prims.op_LessThan", "Spec.P256.PointOps.prime", "Lib.IntTypes.int_t", "Lib.IntTypes.range", "Lib.IntTypes.u64" ]
[]
false
true
false
false
false
let make_g_y n =
[@@ inline_let ]let n0 = u64 0xddf25357ce95560a in [@@ inline_let ]let n1 = u64 0x8b4ab8e4ba19e45c in [@@ inline_let ]let n2 = u64 0xd2e88688dd21f325 in [@@ inline_let ]let n3 = u64 0x8571ff1825885d85 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.g_y == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.g_y; bn_make_u64_4 n n0 n1 n2 n3
false
Hacl.Impl.P256.Constants.fst
Hacl.Impl.P256.Constants.make_a_coeff
val make_a_coeff: a:felem -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_nat h1 a < S.prime /\ SM.from_mont (as_nat h1 a) == S.a_coeff)
val make_a_coeff: a:felem -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_nat h1 a < S.prime /\ SM.from_mont (as_nat h1 a) == S.a_coeff)
let make_a_coeff a = // a_coeff = 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc // a_coeff_mont = 0xfffffffc00000004000000000000000000000003fffffffffffffffffffffffc [@inline_let] let n0 = u64 0xfffffffffffffffc in [@inline_let] let n1 = u64 0x3ffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xfffffffc00000004 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.a_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.a_coeff; bn_make_u64_4 a n0 n1 n2 n3
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.Constants.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 67, "start_col": 0, "start_line": 57 }
module Hacl.Impl.P256.Constants 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 module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val make_prime: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.prime) [@CInline] let make_prime n = // 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff [@inline_let] let n0 = u64 0xffffffffffffffff in [@inline_let] let n1 = u64 0xffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xffffffff00000001 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.prime); bn_make_u64_4 n n0 n1 n2 n3 val make_order: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.order) [@CInline] let make_order n = // 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551 [@inline_let] let n0 = u64 0xf3b9cac2fc632551 in [@inline_let] let n1 = u64 0xbce6faada7179e84 in [@inline_let] let n2 = u64 0xffffffffffffffff in [@inline_let] let n3 = u64 0xffffffff00000000 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.order); bn_make_u64_4 n n0 n1 n2 n3 val make_a_coeff: a:felem -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_nat h1 a < S.prime /\ SM.from_mont (as_nat h1 a) == S.a_coeff)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.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": false, "source_file": "Hacl.Impl.P256.Constants.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "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": 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
a: Hacl.Impl.P256.Bignum.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.P256.Bignum.felem", "Hacl.Impl.P256.Bignum.bn_make_u64_4", "Prims.unit", "Hacl.Spec.P256.Montgomery.lemma_to_from_mont_id", "Spec.P256.PointOps.a_coeff", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Hacl.Spec.P256.Montgomery.to_mont", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Mul.op_Star", "Prims.pow2", "Prims.b2t", "Prims.op_LessThan", "Spec.P256.PointOps.prime", "Lib.IntTypes.int_t", "Lib.IntTypes.range", "Lib.IntTypes.u64" ]
[]
false
true
false
false
false
let make_a_coeff a =
[@@ inline_let ]let n0 = u64 0xfffffffffffffffc in [@@ inline_let ]let n1 = u64 0x3ffffffff in [@@ inline_let ]let n2 = u64 0x0 in [@@ inline_let ]let n3 = u64 0xfffffffc00000004 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.a_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.a_coeff; bn_make_u64_4 a n0 n1 n2 n3
false
Hacl.Impl.P256.Constants.fst
Hacl.Impl.P256.Constants.make_b_coeff
val make_b_coeff: b:felem -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_nat h1 b < S.prime /\ SM.from_mont (as_nat h1 b) == S.b_coeff)
val make_b_coeff: b:felem -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_nat h1 b < S.prime /\ SM.from_mont (as_nat h1 b) == S.b_coeff)
let make_b_coeff b = // b_coeff = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b // b_coeff_mont = 0xdc30061d04874834e5a220abf7212ed6acf005cd78843090d89cdf6229c4bddf [@inline_let] let n0 = u64 0xd89cdf6229c4bddf in [@inline_let] let n1 = u64 0xacf005cd78843090 in [@inline_let] let n2 = u64 0xe5a220abf7212ed6 in [@inline_let] let n3 = u64 0xdc30061d04874834 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.b_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.b_coeff; bn_make_u64_4 b n0 n1 n2 n3
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.Constants.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 87, "start_col": 0, "start_line": 77 }
module Hacl.Impl.P256.Constants 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 module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val make_prime: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.prime) [@CInline] let make_prime n = // 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff [@inline_let] let n0 = u64 0xffffffffffffffff in [@inline_let] let n1 = u64 0xffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xffffffff00000001 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.prime); bn_make_u64_4 n n0 n1 n2 n3 val make_order: n:felem -> Stack unit (requires fun h -> live h n) (ensures fun h0 _ h1 -> modifies (loc n) h0 h1 /\ as_nat h1 n == S.order) [@CInline] let make_order n = // 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551 [@inline_let] let n0 = u64 0xf3b9cac2fc632551 in [@inline_let] let n1 = u64 0xbce6faada7179e84 in [@inline_let] let n2 = u64 0xffffffffffffffff in [@inline_let] let n3 = u64 0xffffffff00000000 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 = S.order); bn_make_u64_4 n n0 n1 n2 n3 val make_a_coeff: a:felem -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_nat h1 a < S.prime /\ SM.from_mont (as_nat h1 a) == S.a_coeff) [@CInline] let make_a_coeff a = // a_coeff = 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc // a_coeff_mont = 0xfffffffc00000004000000000000000000000003fffffffffffffffffffffffc [@inline_let] let n0 = u64 0xfffffffffffffffc in [@inline_let] let n1 = u64 0x3ffffffff in [@inline_let] let n2 = u64 0x0 in [@inline_let] let n3 = u64 0xfffffffc00000004 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.a_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.a_coeff; bn_make_u64_4 a n0 n1 n2 n3 val make_b_coeff: b:felem -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_nat h1 b < S.prime /\ SM.from_mont (as_nat h1 b) == S.b_coeff)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.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": false, "source_file": "Hacl.Impl.P256.Constants.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "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": 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
b: Hacl.Impl.P256.Bignum.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.P256.Bignum.felem", "Hacl.Impl.P256.Bignum.bn_make_u64_4", "Prims.unit", "Hacl.Spec.P256.Montgomery.lemma_to_from_mont_id", "Spec.P256.PointOps.b_coeff", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Hacl.Spec.P256.Montgomery.to_mont", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Mul.op_Star", "Prims.pow2", "Prims.b2t", "Prims.op_LessThan", "Spec.P256.PointOps.prime", "Lib.IntTypes.int_t", "Lib.IntTypes.range", "Lib.IntTypes.u64" ]
[]
false
true
false
false
false
let make_b_coeff b =
[@@ inline_let ]let n0 = u64 0xd89cdf6229c4bddf in [@@ inline_let ]let n1 = u64 0xacf005cd78843090 in [@@ inline_let ]let n2 = u64 0xe5a220abf7212ed6 in [@@ inline_let ]let n3 = u64 0xdc30061d04874834 in assert_norm (v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192 < S.prime); assert_norm (SM.to_mont S.b_coeff == v n0 + v n1 * pow2 64 + v n2 * pow2 128 + v n3 * pow2 192); SM.lemma_to_from_mont_id S.b_coeff; bn_make_u64_4 b n0 n1 n2 n3
false
Lib.IntTypes.fst
Lib.IntTypes.cast_mod
val cast_mod: #t:inttype{signed t} -> #l:secrecy_level -> t':inttype{signed t'} -> l':secrecy_level{PUB? l \/ SEC? l'} -> a:int_t t l -> b:int_t t' l'{v b == v a @%. t'}
val cast_mod: #t:inttype{signed t} -> #l:secrecy_level -> t':inttype{signed t'} -> l':secrecy_level{PUB? l \/ SEC? l'} -> a:int_t t l -> b:int_t t' l'{v b == v a @%. t'}
let cast_mod #t #l t' l' a = assert_norm (pow2 7 = 128); assert_norm (pow2 15 = 32768); if bits t' >= bits t then cast t' l' a else begin let m = size (bits t') in mod_mask_lemma a m; let b = conditional_subtract t' (a `logand` mod_mask m) in cast t' l' b end
{ "file_name": "lib/Lib.IntTypes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 7, "end_line": 1022, "start_col": 0, "start_line": 1011 }
module Lib.IntTypes open FStar.Math.Lemmas #push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200" let pow2_2 _ = assert_norm (pow2 2 = 4) let pow2_3 _ = assert_norm (pow2 3 = 8) let pow2_4 _ = assert_norm (pow2 4 = 16) let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000) let bits_numbytes t = () let sec_int_t t = pub_int_t t let sec_int_v #t u = pub_int_v u let secret #t x = x [@(strict_on_arguments [0])] let mk_int #t #l x = match t with | U1 -> UInt8.uint_to_t x | U8 -> UInt8.uint_to_t x | U16 -> UInt16.uint_to_t x | U32 -> UInt32.uint_to_t x | U64 -> UInt64.uint_to_t x | U128 -> UInt128.uint_to_t x | S8 -> Int8.int_to_t x | S16 -> Int16.int_to_t x | S32 -> Int32.int_to_t x | S64 -> Int64.int_to_t x | S128 -> Int128.int_to_t x val v_extensionality: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma (requires v a == v b) (ensures a == b) let v_extensionality #t #l a b = match t with | U1 -> () | U8 -> UInt8.v_inj a b | U16 -> UInt16.v_inj a b | U32 -> UInt32.v_inj a b | U64 -> UInt64.v_inj a b | U128 -> UInt128.v_inj a b | S8 -> Int8.v_inj a b | S16 -> Int16.v_inj a b | S32 -> Int32.v_inj a b | S64 -> Int64.v_inj a b | S128 -> Int128.v_inj a b let v_injective #t #l a = v_extensionality a (mk_int (v a)) let v_mk_int #t #l n = () let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n) // KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided // We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals let i128 n = assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1)); sint #S128 #SEC n let size_to_uint32 x = x let size_to_uint64 x = Int.Cast.uint32_to_uint64 x let byte_to_uint8 x = x let byte_to_int8 x = Int.Cast.uint8_to_int8 x let op_At_Percent = Int.op_At_Percent // FStar.UInt128 gets special treatment in KaRaMeL. There is no // equivalent for FStar.Int128 at the moment, so we use the three // assumed cast operators below. // // Using them will fail at runtime with an informative message. // The commented-out implementations show that they are realizable. // // When support for `FStar.Int128` is added KaRaMeL, these casts must // be added as special cases. When using builtin compiler support for // `int128_t`, they can be implemented directly as C casts without // undefined or implementation-defined behaviour. assume val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a} //let uint128_to_int128 a = Int128.int_to_t (v a) assume val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128} //let int128_to_uint128 a = mk_int (v a % pow2 128) assume val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a} //let int64_to_int128 a = Int128.int_to_t (v a) val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a} let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a) val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128} let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a) val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64} let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a) #push-options "--z3rlimit 1000" [@(strict_on_arguments [0;2])] let cast #t #l t' l' u = assert_norm (pow2 8 = 2 * pow2 7); assert_norm (pow2 16 = 2 * pow2 15); assert_norm (pow2 64 * pow2 64 = pow2 128); assert_norm (pow2 16 * pow2 48 = pow2 64); assert_norm (pow2 8 * pow2 56 = pow2 64); assert_norm (pow2 32 * pow2 32 = pow2 64); modulo_modulo_lemma (v u) (pow2 32) (pow2 32); modulo_modulo_lemma (v u) (pow2 64) (pow2 64); modulo_modulo_lemma (v u) (pow2 128) (pow2 64); modulo_modulo_lemma (v u) (pow2 16) (pow2 48); modulo_modulo_lemma (v u) (pow2 8) (pow2 56); let open FStar.Int.Cast in let open FStar.Int.Cast.Full in match t, t' with | U1, U1 -> u | U1, U8 -> u | U1, U16 -> uint8_to_uint16 u | U1, U32 -> uint8_to_uint32 u | U1, U64 -> uint8_to_uint64 u | U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u) | U1, S8 -> uint8_to_int8 u | U1, S16 -> uint8_to_int16 u | U1, S32 -> uint8_to_int32 u | U1, S64 -> uint8_to_int64 u | U1, S128 -> uint64_to_int128 (uint8_to_uint64 u) | U8, U1 -> UInt8.rem u 2uy | U8, U8 -> u | U8, U16 -> uint8_to_uint16 u | U8, U32 -> uint8_to_uint32 u | U8, U64 -> uint8_to_uint64 u | U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u) | U8, S8 -> uint8_to_int8 u | U8, S16 -> uint8_to_int16 u | U8, S32 -> uint8_to_int32 u | U8, S64 -> uint8_to_int64 u | U8, S128 -> uint64_to_int128 (uint8_to_uint64 u) | U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy | U16, U8 -> uint16_to_uint8 u | U16, U16 -> u | U16, U32 -> uint16_to_uint32 u | U16, U64 -> uint16_to_uint64 u | U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u) | U16, S8 -> uint16_to_int8 u | U16, S16 -> uint16_to_int16 u | U16, S32 -> uint16_to_int32 u | U16, S64 -> uint16_to_int64 u | U16, S128 -> uint64_to_int128 (uint16_to_uint64 u) | U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy | U32, U8 -> uint32_to_uint8 u | U32, U16 -> uint32_to_uint16 u | U32, U32 -> u | U32, U64 -> uint32_to_uint64 u | U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u) | U32, S8 -> uint32_to_int8 u | U32, S16 -> uint32_to_int16 u | U32, S32 -> uint32_to_int32 u | U32, S64 -> uint32_to_int64 u | U32, S128 -> uint64_to_int128 (uint32_to_uint64 u) | U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy | U64, U8 -> uint64_to_uint8 u | U64, U16 -> uint64_to_uint16 u | U64, U32 -> uint64_to_uint32 u | U64, U64 -> u | U64, U128 -> UInt128.uint64_to_uint128 u | U64, S8 -> uint64_to_int8 u | U64, S16 -> uint64_to_int16 u | U64, S32 -> uint64_to_int32 u | U64, S64 -> uint64_to_int64 u | U64, S128 -> uint64_to_int128 u | U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy | U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u) | U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u) | U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u) | U128, U64 -> UInt128.uint128_to_uint64 u | U128, U128 -> u | U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u) | U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u) | U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u) | U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u) | U128, S128 -> uint128_to_int128 u | S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy | S8, U8 -> int8_to_uint8 u | S8, U16 -> int8_to_uint16 u | S8, U32 -> int8_to_uint32 u | S8, U64 -> int8_to_uint64 u | S8, U128 -> int64_to_uint128 (int8_to_int64 u) | S8, S8 -> u | S8, S16 -> int8_to_int16 u | S8, S32 -> int8_to_int32 u | S8, S64 -> int8_to_int64 u | S8, S128 -> int64_to_int128 (int8_to_int64 u) | S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy | S16, U8 -> int16_to_uint8 u | S16, U16 -> int16_to_uint16 u | S16, U32 -> int16_to_uint32 u | S16, U64 -> int16_to_uint64 u | S16, U128 -> int64_to_uint128 (int16_to_int64 u) | S16, S8 -> int16_to_int8 u | S16, S16 -> u | S16, S32 -> int16_to_int32 u | S16, S64 -> int16_to_int64 u | S16, S128 -> int64_to_int128 (int16_to_int64 u) | S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy | S32, U8 -> int32_to_uint8 u | S32, U16 -> int32_to_uint16 u | S32, U32 -> int32_to_uint32 u | S32, U64 -> int32_to_uint64 u | S32, U128 -> int64_to_uint128 (int32_to_int64 u) | S32, S8 -> int32_to_int8 u | S32, S16 -> int32_to_int16 u | S32, S32 -> u | S32, S64 -> int32_to_int64 u | S32, S128 -> int64_to_int128 (int32_to_int64 u) | S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy | S64, U8 -> int64_to_uint8 u | S64, U16 -> int64_to_uint16 u | S64, U32 -> int64_to_uint32 u | S64, U64 -> int64_to_uint64 u | S64, U128 -> int64_to_uint128 u | S64, S8 -> int64_to_int8 u | S64, S16 -> int64_to_int16 u | S64, S32 -> int64_to_int32 u | S64, S64 -> u | S64, S128 -> int64_to_int128 u | S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy | S128, U8 -> uint64_to_uint8 (int128_to_uint64 u) | S128, U16 -> uint64_to_uint16 (int128_to_uint64 u) | S128, U32 -> uint64_to_uint32 (int128_to_uint64 u) | S128, U64 -> int128_to_uint64 u | S128, U128 -> int128_to_uint128 u | S128, S8 -> uint64_to_int8 (int128_to_uint64 u) | S128, S16 -> uint64_to_int16 (int128_to_uint64 u) | S128, S32 -> uint64_to_int32 (int128_to_uint64 u) | S128, S64 -> uint64_to_int64 (int128_to_uint64 u) | S128, S128 -> u #pop-options [@(strict_on_arguments [0])] let ones t l = match t with | U1 -> 0x1uy | U8 -> 0xFFuy | U16 -> 0xFFFFus | U32 -> 0xFFFFFFFFul | U64 -> 0xFFFFFFFFFFFFFFFFuL | U128 -> let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in let y = (UInt128.shift_left x 64ul) `UInt128.add` x in assert_norm (UInt128.v y == pow2 128 - 1); y | _ -> mk_int (-1) let zeros t l = mk_int 0 [@(strict_on_arguments [0])] let add_mod #t #l a b = match t with | U1 -> UInt8.rem (UInt8.add_mod a b) 2uy | U8 -> UInt8.add_mod a b | U16 -> UInt16.add_mod a b | U32 -> UInt32.add_mod a b | U64 -> UInt64.add_mod a b | U128 -> UInt128.add_mod a b let add_mod_lemma #t #l a b = () [@(strict_on_arguments [0])] let add #t #l a b = match t with | U1 -> UInt8.add a b | U8 -> UInt8.add a b | U16 -> UInt16.add a b | U32 -> UInt32.add a b | U64 -> UInt64.add a b | U128 -> UInt128.add a b | S8 -> Int8.add a b | S16 -> Int16.add a b | S32 -> Int32.add a b | S64 -> Int64.add a b | S128 -> Int128.add a b let add_lemma #t #l a b = () #push-options "--max_fuel 1" [@(strict_on_arguments [0])] let incr #t #l a = match t with | U1 -> UInt8.add a 1uy | U8 -> UInt8.add a 1uy | U16 -> UInt16.add a 1us | U32 -> UInt32.add a 1ul | U64 -> UInt64.add a 1uL | U128 -> UInt128.add a (UInt128.uint_to_t 1) | S8 -> Int8.add a 1y | S16 -> Int16.add a 1s | S32 -> Int32.add a 1l | S64 -> Int64.add a 1L | S128 -> Int128.add a (Int128.int_to_t 1) let incr_lemma #t #l a = () #pop-options [@(strict_on_arguments [0])] let mul_mod #t #l a b = match t with | U1 -> UInt8.mul_mod a b | U8 -> UInt8.mul_mod a b | U16 -> UInt16.mul_mod a b | U32 -> UInt32.mul_mod a b | U64 -> UInt64.mul_mod a b let mul_mod_lemma #t #l a b = () [@(strict_on_arguments [0])] let mul #t #l a b = match t with | U1 -> UInt8.mul a b | U8 -> UInt8.mul a b | U16 -> UInt16.mul a b | U32 -> UInt32.mul a b | U64 -> UInt64.mul a b | S8 -> Int8.mul a b | S16 -> Int16.mul a b | S32 -> Int32.mul a b | S64 -> Int64.mul a b let mul_lemma #t #l a b = () let mul64_wide a b = UInt128.mul_wide a b let mul64_wide_lemma a b = () let mul_s64_wide a b = Int128.mul_wide a b let mul_s64_wide_lemma a b = () [@(strict_on_arguments [0])] let sub_mod #t #l a b = match t with | U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy | U8 -> UInt8.sub_mod a b | U16 -> UInt16.sub_mod a b | U32 -> UInt32.sub_mod a b | U64 -> UInt64.sub_mod a b | U128 -> UInt128.sub_mod a b let sub_mod_lemma #t #l a b = () [@(strict_on_arguments [0])] let sub #t #l a b = match t with | U1 -> UInt8.sub a b | U8 -> UInt8.sub a b | U16 -> UInt16.sub a b | U32 -> UInt32.sub a b | U64 -> UInt64.sub a b | U128 -> UInt128.sub a b | S8 -> Int8.sub a b | S16 -> Int16.sub a b | S32 -> Int32.sub a b | S64 -> Int64.sub a b | S128 -> Int128.sub a b let sub_lemma #t #l a b = () #push-options "--max_fuel 1" [@(strict_on_arguments [0])] let decr #t #l a = match t with | U1 -> UInt8.sub a 1uy | U8 -> UInt8.sub a 1uy | U16 -> UInt16.sub a 1us | U32 -> UInt32.sub a 1ul | U64 -> UInt64.sub a 1uL | U128 -> UInt128.sub a (UInt128.uint_to_t 1) | S8 -> Int8.sub a 1y | S16 -> Int16.sub a 1s | S32 -> Int32.sub a 1l | S64 -> Int64.sub a 1L | S128 -> Int128.sub a (Int128.int_to_t 1) let decr_lemma #t #l a = () #pop-options [@(strict_on_arguments [0])] let logxor #t #l a b = match t with | U1 -> assert_norm (UInt8.logxor 0uy 0uy == 0uy); assert_norm (UInt8.logxor 0uy 1uy == 1uy); assert_norm (UInt8.logxor 1uy 0uy == 1uy); assert_norm (UInt8.logxor 1uy 1uy == 0uy); UInt8.logxor a b | U8 -> UInt8.logxor a b | U16 -> UInt16.logxor a b | U32 -> UInt32.logxor a b | U64 -> UInt64.logxor a b | U128 -> UInt128.logxor a b | S8 -> Int8.logxor a b | S16 -> Int16.logxor a b | S32 -> Int32.logxor a b | S64 -> Int64.logxor a b | S128 -> Int128.logxor a b #push-options "--max_fuel 1" val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma (v (a `logxor` (a `logxor` b)) == v b) let logxor_lemma_ #t #l a b = match t with | U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_associative #(bits t) (v a) (v a) (v b); UInt.logxor_self #(bits t) (v a); UInt.logxor_commutative #(bits t) 0 (v b); UInt.logxor_lemma_1 #(bits t) (v b) | S8 | S16 | S32 | S64 | S128 -> Int.logxor_associative #(bits t) (v a) (v a) (v b); Int.logxor_self #(bits t) (v a); Int.logxor_commutative #(bits t) 0 (v b); Int.logxor_lemma_1 #(bits t) (v b) let logxor_lemma #t #l a b = logxor_lemma_ #t a b; v_extensionality (logxor a (logxor a b)) b; begin match t with | U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b) | S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b) end; v_extensionality (logxor a (logxor b a)) b; begin match t with | U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a) | S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a) end; v_extensionality (logxor a (mk_int #t #l 0)) a let logxor_lemma1 #t #l a b = match v a, v b with | _, 0 -> UInt.logxor_lemma_1 #(bits t) (v a) | 0, _ -> UInt.logxor_commutative #(bits t) (v a) (v b); UInt.logxor_lemma_1 #(bits t) (v b) | 1, 1 -> v_extensionality a b; UInt.logxor_self #(bits t) (v a) let logxor_spec #t #l a b = match t with | U1 -> assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1); assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0); assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1); assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0) | _ -> () #pop-options [@(strict_on_arguments [0])] let logand #t #l a b = match t with | U1 -> assert_norm (UInt8.logand 0uy 0uy == 0uy); assert_norm (UInt8.logand 0uy 1uy == 0uy); assert_norm (UInt8.logand 1uy 0uy == 0uy); assert_norm (UInt8.logand 1uy 1uy == 1uy); UInt8.logand a b | U8 -> UInt8.logand a b | U16 -> UInt16.logand a b | U32 -> UInt32.logand a b | U64 -> UInt64.logand a b | U128 -> UInt128.logand a b | S8 -> Int8.logand a b | S16 -> Int16.logand a b | S32 -> Int32.logand a b | S64 -> Int64.logand a b | S128 -> Int128.logand a b let logand_zeros #t #l a = match t with | U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0) | U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a) | S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a) let logand_ones #t #l a = match t with | U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1) | U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a) | S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a) let logand_lemma #t #l a b = logand_zeros #t #l b; logand_ones #t #l b; match t with | U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0); assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1) | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b) | S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b) let logand_spec #t #l a b = match t with | U1 -> assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0); assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1); assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0); assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1) | _ -> () let logand_le #t #l a b = match t with | U1 -> assert_norm (UInt8.logand 0uy 0uy == 0uy); assert_norm (UInt8.logand 0uy 1uy == 0uy); assert_norm (UInt8.logand 1uy 0uy == 0uy); assert_norm (UInt8.logand 1uy 1uy == 1uy) | U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b)) | U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b)) | U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b)) | U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b)) | U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b)) let logand_mask #t #l a b m = match t with | U1 -> assert_norm (UInt8.logand 0uy 0uy == 0uy); assert_norm (UInt8.logand 0uy 1uy == 0uy); assert_norm (UInt8.logand 1uy 0uy == 0uy); assert_norm (UInt8.logand 1uy 1uy == 1uy) | U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m | U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m | U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m | U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m | U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m [@(strict_on_arguments [0])] let logor #t #l a b = match t with | U1 -> assert_norm (UInt8.logor 0uy 0uy == 0uy); assert_norm (UInt8.logor 0uy 1uy == 1uy); assert_norm (UInt8.logor 1uy 0uy == 1uy); assert_norm (UInt8.logor 1uy 1uy == 1uy); UInt8.logor a b | U8 -> UInt8.logor a b | U16 -> UInt16.logor a b | U32 -> UInt32.logor a b | U64 -> UInt64.logor a b | U128 -> UInt128.logor a b | S8 -> Int8.logor a b | S16 -> Int16.logor a b | S32 -> Int32.logor a b | S64 -> Int64.logor a b | S128 -> Int128.logor a b #push-options "--max_fuel 1" let logor_disjoint #t #l a b m = if m > 0 then begin UInt.logor_disjoint #(bits t) (v b) (v a) m; UInt.logor_commutative #(bits t) (v b) (v a) end else begin UInt.logor_commutative #(bits t) (v a) (v b); UInt.logor_lemma_1 #(bits t) (v b) end #pop-options let logor_zeros #t #l a = match t with |U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1) | U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a) | S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a) let logor_ones #t #l a = match t with |U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1) | U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a) | S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t)) let logor_lemma #t #l a b = logor_zeros #t #l b; logor_ones #t #l b; match t with | U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1); assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1) | U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b) | S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a)) let logor_spec #t #l a b = match t with | U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1); assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1); assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1); assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1) | _ -> () [@(strict_on_arguments [0])] let lognot #t #l a = match t with | U1 -> UInt8.rem (UInt8.lognot a) 2uy | U8 -> UInt8.lognot a | U16 -> UInt16.lognot a | U32 -> UInt32.lognot a | U64 -> UInt64.lognot a | U128 -> UInt128.lognot a | S8 -> Int8.lognot a | S16 -> Int16.lognot a | S32 -> Int32.lognot a | S64 -> Int64.lognot a | S128 -> Int128.lognot a let lognot_lemma #t #l a = match t with |U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0) | U8 | U16 | U32 | U64 | U128 -> FStar.UInt.lognot_lemma_1 #(bits t); UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t)) | S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t)); Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t)) let lognot_spec #t #l a = match t with | U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0); assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0) | _ -> () [@(strict_on_arguments [0])] let shift_right #t #l a b = match t with | U1 -> UInt8.shift_right a b | U8 -> UInt8.shift_right a b | U16 -> UInt16.shift_right a b | U32 -> UInt32.shift_right a b | U64 -> UInt64.shift_right a b | U128 -> UInt128.shift_right a b | S8 -> Int8.shift_arithmetic_right a b | S16 -> Int16.shift_arithmetic_right a b | S32 -> Int32.shift_arithmetic_right a b | S64 -> Int64.shift_arithmetic_right a b | S128 -> Int128.shift_arithmetic_right a b val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} -> Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s) let shift_right_value_aux_1 #n a s = pow2_le_compat s n; if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a #push-options "--z3rlimit 200" val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n -> Lemma (Int.shift_arithmetic_right #n a 1 = a / 2) let shift_right_value_aux_2 #n a = if a >= 0 then begin Int.sign_bit_positive a; UInt.shift_right_value_aux_3 #n a 1 end else begin Int.sign_bit_negative a; let a1 = Int.to_vec a in let au = Int.to_uint a in let sar = Int.shift_arithmetic_right #n a 1 in let sar1 = Int.to_vec sar in let sr = UInt.shift_right #n au 1 in let sr1 = UInt.to_vec sr in assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n)); assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n))); UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n); assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n)); UInt.slice_left_lemma a1 (n-1); assert (sar + pow2 n = pow2 (n-1) + (au / 2)); pow2_double_sum (n-1); assert (sar + pow2 (n-1) = (a + pow2 n) / 2); pow2_double_mult (n-1); lemma_div_plus a (pow2 (n-1)) 2; assert (sar = a / 2) end val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} -> Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s) (decreases s) let rec shift_right_value_aux_3 #n a s = if s = 1 then shift_right_value_aux_2 #n a else begin let a1 = Int.to_vec a in assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s) (BitVector.shift_arithmetic_right_vec #n (BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1)); assert (Int.shift_arithmetic_right #n a s = Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1); shift_right_value_aux_3 #n a (s-1); shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1)); assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2); pow2_double_mult (s-1); division_multiplication_lemma a (pow2 (s-1)) 2 end let shift_right_lemma #t #l a b = match t with | U1 | U8 | U16 | U32 | U64 | U128 -> () | S8 | S16 | S32 | S64 | S128 -> if v b = 0 then () else if v b >= bits t then shift_right_value_aux_1 #(bits t) (v a) (v b) else shift_right_value_aux_3 #(bits t) (v a) (v b) [@(strict_on_arguments [0])] let shift_left #t #l a b = match t with | U1 -> UInt8.shift_left a b | U8 -> UInt8.shift_left a b | U16 -> UInt16.shift_left a b | U32 -> UInt32.shift_left a b | U64 -> UInt64.shift_left a b | U128 -> UInt128.shift_left a b | S8 -> Int8.shift_left a b | S16 -> Int16.shift_left a b | S32 -> Int32.shift_left a b | S64 -> Int64.shift_left a b | S128 -> Int128.shift_left a b #push-options "--max_fuel 1" let shift_left_lemma #t #l a b = () let rotate_right #t #l a b = logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b)) let rotate_left #t #l a b = logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b)) [@(strict_on_arguments [0])] let ct_abs #t #l a = match t with | S8 -> Int8.ct_abs a | S16 -> Int16.ct_abs a | S32 -> Int32.ct_abs a | S64 -> Int64.ct_abs a #pop-options [@(strict_on_arguments [0])] let eq_mask #t a b = match t with | U1 -> lognot (logxor a b) | U8 -> UInt8.eq_mask a b | U16 -> UInt16.eq_mask a b | U32 -> UInt32.eq_mask a b | U64 -> UInt64.eq_mask a b | U128 -> UInt128.eq_mask a b | S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b)) | S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b)) | S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b)) | S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b)) val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma (if v a = v b then v (eq_mask a b) == ones_v t else v (eq_mask a b) == 0) let eq_mask_lemma_unsigned #t a b = match t with | U1 -> assert_norm ( logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\ logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\ lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1) | U8 | U16 | U32 | U64 | U128 -> () #push-options "--z3rlimit 200" val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma (if v a = v b then v (eq_mask a b) == ones_v t else v (eq_mask a b) == 0) let eq_mask_lemma_signed #t a b = match t with | S8 -> begin assert_norm (pow2 8 = 2 * pow2 7); if 0 <= v a then modulo_lemma (v a) (pow2 8) else begin modulo_addition_lemma (v a) 1 (pow2 8); modulo_lemma (v a + pow2 8) (pow2 8) end end | S16 -> begin assert_norm (pow2 16 = 2 * pow2 15); if 0 <= v a then modulo_lemma (v a) (pow2 16) else begin modulo_addition_lemma (v a) 1 (pow2 16); modulo_lemma (v a + pow2 16) (pow2 16) end end | S32 -> begin if 0 <= v a then modulo_lemma (v a) (pow2 32) else begin modulo_addition_lemma (v a) 1 (pow2 32); modulo_lemma (v a + pow2 32) (pow2 32) end end | S64 -> begin if 0 <= v a then modulo_lemma (v a) (pow2 64) else begin modulo_addition_lemma (v a) 1 (pow2 64); modulo_lemma (v a + pow2 64) (pow2 64) end end #pop-options let eq_mask_lemma #t a b = if signed t then eq_mask_lemma_signed a b else eq_mask_lemma_unsigned a b let eq_mask_logand_lemma #t a b c = eq_mask_lemma a b; logand_zeros c; logand_ones c; match t with | U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c) | S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c) [@(strict_on_arguments [0])] let neq_mask #t a b = lognot (eq_mask #t a b) let neq_mask_lemma #t a b = match t with | U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1) | _ -> UInt.lognot_lemma_1 #(bits t); UInt.lognot_self #(bits t) 0 [@(strict_on_arguments [0])] let gte_mask #t a b = match t with | U1 -> logor a (lognot b) | U8 -> UInt8.gte_mask a b | U16 -> UInt16.gte_mask a b | U32 -> UInt32.gte_mask a b | U64 -> UInt64.gte_mask a b | U128 -> UInt128.gte_mask a b let gte_mask_lemma #t a b = match t with | U1 -> begin assert_norm ( logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\ logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\ lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1) end | _ -> () let gte_mask_logand_lemma #t a b c = logand_zeros c; logand_ones c; match t with | U1 -> assert_norm ( logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\ logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\ lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1) | _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c) let lt_mask #t a b = lognot (gte_mask a b) let lt_mask_lemma #t a b = assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1); UInt.lognot_lemma_1 #(bits t); UInt.lognot_self #(bits t) 0 let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b) let gt_mask_lemma #t a b = logand_zeros (gte_mask a b); logand_ones (gte_mask a b) let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b) let lte_mask_lemma #t a b = match t with | U1 -> assert_norm ( logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\ logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1) | U8 | U16 | U32 | U64 | U128 -> if v a > v b then UInt.logor_lemma_1 #(bits t) (v (lt_mask a b)) else if v a = v b then UInt.logor_lemma_2 #(bits t) (v (lt_mask a b)) else UInt.logor_lemma_1 #(bits t) (v (lt_mask a b)) #push-options "--max_fuel 1" val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} -> Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1) let mod_mask_value #t #l m = shift_left_lemma (mk_int #t #l 1) m; pow2_double_mult (bits t - 1); pow2_lt_compat (bits t) (v m); small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t)); small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t)) let mod_mask_lemma #t #l a m = mod_mask_value #t #l m; if unsigned t || 0 <= v a then if v m = 0 then UInt.logand_lemma_1 #(bits t) (v a) else UInt.logand_mask #(bits t) (v a) (v m) else begin let a1 = v a in let a2 = v a + pow2 (bits t) in pow2_plus (bits t - v m) (v m); pow2_le_compat (bits t - 1) (v m); lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m)); if v m = 0 then UInt.logand_lemma_1 #(bits t) a2 else UInt.logand_mask #(bits t) a2 (v m) end #pop-options #push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000" (** Conditionally subtracts 2^(bits t') from a in constant-time, so that the result fits in t'; i.e. b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a *) inline_for_extraction val conditional_subtract: #t:inttype{signed t} -> #l:secrecy_level -> t':inttype{signed t' /\ bits t' < bits t} -> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1} -> b:int_t t l{v b = v a @%. t'} let conditional_subtract #t #l t' a = assert_norm (pow2 7 = 128); assert_norm (pow2 15 = 32768); let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in shift_left_lemma #t #l (mk_int 1) (size (bits t')); let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1)); // assert (v pow2_bits == pow2 (bits t')); // assert (v pow2_bits_minus_one == pow2 (bits t' - 1)); let a2 = a `sub` pow2_bits_minus_one in let mask = shift_right a2 (size (bits t - 1)) in shift_right_lemma a2 (size (bits t - 1)); // assert (if v a2 < 0 then v mask = -1 else v mask = 0); let a3 = a `sub` pow2_bits in logand_lemma mask pow2_bits; a3 `add` (mask `logand` pow2_bits)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.Cast.Full.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Int.fsti.checked", "FStar.BitVector.fst.checked" ], "interface_file": true, "source_file": "Lib.IntTypes.fst" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1000, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t': Lib.IntTypes.inttype{Lib.IntTypes.signed t'} -> l': Lib.IntTypes.secrecy_level{PUB? l \/ SEC? l'} -> a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t' l' {Lib.IntTypes.v b == Lib.IntTypes.v a @%. t'}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.inttype", "Prims.b2t", "Lib.IntTypes.signed", "Lib.IntTypes.secrecy_level", "Prims.l_or", "Lib.IntTypes.uu___is_PUB", "Lib.IntTypes.uu___is_SEC", "Lib.IntTypes.int_t", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.bits", "Lib.IntTypes.cast", "Prims.bool", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.op_At_Percent_Dot", "Lib.IntTypes.logand", "Lib.IntTypes.mod_mask", "Lib.IntTypes.conditional_subtract", "Prims.unit", "Lib.IntTypes.mod_mask_lemma", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.size", "Prims.eq2", "FStar.Pervasives.assert_norm", "Prims.pow2" ]
[]
false
false
false
false
false
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128); assert_norm (pow2 15 = 32768); if bits t' >= bits t then cast t' l' a else let m = size (bits t') in mod_mask_lemma a m; let b = conditional_subtract t' (a `logand` (mod_mask m)) in cast t' l' b
false
Lib.Sequence.fst
Lib.Sequence.index_map_blocks_multi
val index_map_blocks_multi: #a:Type0 -> bs:size_pos -> max:pos -> n:pos{n <= max} -> inp:seq a{length inp == max * bs} -> f:(i:nat{i < max} -> lseq a bs -> lseq a bs) -> i:nat{i < n * bs} -> Lemma ( div_mul_lt bs i n; let j = i / bs in let block: lseq a bs = Seq.slice inp (j * bs) ((j + 1) * bs) in Seq.index (map_blocks_multi bs max n inp f) i == Seq.index (f j block) (i % bs))
val index_map_blocks_multi: #a:Type0 -> bs:size_pos -> max:pos -> n:pos{n <= max} -> inp:seq a{length inp == max * bs} -> f:(i:nat{i < max} -> lseq a bs -> lseq a bs) -> i:nat{i < n * bs} -> Lemma ( div_mul_lt bs i n; let j = i / bs in let block: lseq a bs = Seq.slice inp (j * bs) ((j + 1) * bs) in Seq.index (map_blocks_multi bs max n inp f) i == Seq.index (f j block) (i % bs))
let rec index_map_blocks_multi #a bs max n inp f i = let map_blocks_a = map_blocks_a a bs max in let map_blocks_f = map_blocks_f #a bs max inp f in let acc0 = Seq.empty #a in let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n-1); let s = repeat_gen (n-1) map_blocks_a map_blocks_f acc0 in //assert (s1 == map_blocks_f (n-1) s); let s' = f (n-1) (Seq.slice inp ((n-1)*bs) (n*bs)) in //assert (s1 == Seq.append s s'); if i < (n-1)*bs then begin Seq.lemma_index_app1 s s' i; index_map_blocks_multi #a bs max (n-1) inp f i end else begin Seq.lemma_index_app2 s s' i; mod_prop bs (n-1) i end
{ "file_name": "lib/Lib.Sequence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 287, "start_col": 0, "start_line": 271 }
module Lib.Sequence open FStar.Mul open Lib.IntTypes open Lib.LoopCombinators #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq +Lib.IntTypes +Lib.Sequence'" let index #a #len s n = Seq.index s n let create #a len init = Seq.create #a len init let concat #a #len0 #len1 s0 s1 = Seq.append s0 s1 let to_list #a s = Seq.seq_to_list s let of_list #a l = Seq.seq_of_list #a l let of_list_index #a l i = Seq.lemma_seq_of_list_index #a l i let equal #a #len s1 s2 = forall (i:size_nat{i < len}).{:pattern (index s1 i); (index s2 i)} index s1 i == index s2 i let eq_intro #a #len s1 s2 = assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)} index s1 i == index s2 i); Seq.lemma_eq_intro #a (to_seq s1) (to_seq s2) let eq_elim #a #len s1 s2 = assert (forall (i:nat{i < len}).{:pattern (Seq.index s1 i); (Seq.index s2 i)} index s1 i == index s2 i); Seq.lemma_eq_elim #a s1 s2 let upd #a #len s n x = Seq.upd #a s n x let member #a #len x l = Seq.count x l > 0 let sub #a #len s start n = Seq.slice #a s start (start + n) let update_sub #a #len s start n x = let o = Seq.append (Seq.append (Seq.slice s 0 start) x) (Seq.slice s (start + n) (length s)) in Seq.lemma_eq_intro (Seq.slice o start (start + n)) x; o let lemma_update_sub #a #len dst start n src res = let res1 = update_sub dst start n src in Seq.lemma_split (sub res 0 (start + n)) start; Seq.lemma_split (sub res1 0 (start + n)) start; Seq.lemma_split res (start + n); Seq.lemma_split res1 (start + n); Seq.lemma_eq_intro res (update_sub dst start n src) let lemma_concat2 #a len0 s0 len1 s1 s = Seq.Properties.lemma_split s len0; Seq.Properties.lemma_split (concat s0 s1) len0; Seq.lemma_eq_intro s (concat s0 s1) let lemma_concat3 #a len0 s0 len1 s1 len2 s2 s = let s' = concat (concat s0 s1) s2 in Seq.Properties.lemma_split (sub s 0 (len0 + len1)) len0; Seq.Properties.lemma_split (sub s' 0 (len0 + len1)) len0; Seq.Properties.lemma_split s (len0 + len1); Seq.Properties.lemma_split s' (len0 + len1); Seq.lemma_eq_intro s (concat (concat s0 s1) s2) let createi_a (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) = lseq a k let createi_pred (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (k:nat{k <= len}) (s:createi_a a len init k) = forall (i:nat).{:pattern (index s i)} i < k ==> index s i == init i let createi_step (a:Type) (len:size_nat) (init:(i:nat{i < len} -> a)) (i:nat{i < len}) (si:createi_a a len init i) : r:createi_a a len init (i + 1) {createi_pred a len init i si ==> createi_pred a len init (i + 1) r} = assert (createi_pred a len init i si ==> (forall (j:nat). j < i ==> index si j == init j)); Seq.snoc si (init i) #push-options "--max_fuel 1 --using_facts_from '+Lib.LoopCombinators +FStar.List'" let createi #a len init_f = repeat_gen_inductive len (createi_a a len init_f) (createi_pred a len init_f) (createi_step a len init_f) (of_list []) #pop-options inline_for_extraction let mapi_inner (#a:Type) (#b:Type) (#len:size_nat) (f:(i:nat{i < len} -> a -> b)) (s:lseq a len) (i:size_nat{i < len}) = f i s.[i] let mapi #a #b #len f s = createi #b len (mapi_inner #a #b #len f s) inline_for_extraction let map_inner (#a:Type) (#b:Type) (#len:size_nat) (f:(a -> Tot b)) (s:lseq a len) (i:size_nat{i < len}) = f s.[i] let map #a #b #len f s = createi #b len (map_inner #a #b #len f s) let map2i #a #b #c #len f s1 s2 = createi #c len (fun i -> f i s1.[i] s2.[i]) inline_for_extraction let map2_inner (#a:Type) (#b:Type) (#c:Type) (#len:size_nat) (f:(a -> b -> Tot c)) (s1:lseq a len) (s2:lseq b len) (i:size_nat{i < len}) = f s1.[i] s2.[i] let map2 #a #b #c #len f s1 s2 = createi #c len (map2_inner #a #b #c #len f s1 s2) let for_all #a #len f x = Seq.for_all f x let for_all2 #a #b #len f x y = let r = map2 (fun xi yi -> f xi yi) x y in Seq.for_all (fun bi -> bi = true) r (** Selecting a subset of an unbounded Sequence *) val seq_sub: #a:Type -> s1:seq a -> start:nat -> n:nat{start + n <= length s1} -> s2:seq a{length s2 == n /\ (forall (k:nat{k < n}). {:pattern (Seq.index s2 k)} Seq.index s2 k == Seq.index s1 (start + k))} let seq_sub #a s start n = Seq.slice #a s start (start + n) (** Updating a subset of an unbounded Sequence with another Sequence *) val seq_update_sub: #a:Type -> i:seq a -> start:nat -> n:nat{start + n <= length i} -> x:seq a{length x == n} -> o:seq a{length o == length i /\ seq_sub o start n == x /\ (forall (k:nat{(0 <= k /\ k < start) \/ (start + n <= k /\ k < length i)}). {:pattern (Seq.index o k)} Seq.index o k == Seq.index i k)} let seq_update_sub #a s start n x = let o = Seq.append (Seq.append (Seq.slice s 0 start) x) (Seq.slice s (start + n) (length s)) in Seq.lemma_eq_intro (Seq.slice o start (start + n)) x; o val repeati_blocks_f: #a:Type0 -> #b:Type0 -> blocksize:size_nat{blocksize > 0} -> inp:seq a -> f:(i:nat{i < length inp / blocksize} -> lseq a blocksize -> b -> b) -> nb:nat{nb == length inp / blocksize} -> i:nat{i < nb} -> acc:b -> b let repeati_blocks_f #a #b bs inp f nb i acc = assert ((i+1) * bs <= nb * bs); let block = seq_sub inp (i * bs) bs in f i block acc let repeati_blocks #a #b bs inp f g init = let len = length inp in let nb = len / bs in let rem = len % bs in let acc = repeati nb (repeati_blocks_f bs inp f nb) init in let last = seq_sub inp (nb * bs) rem in g nb rem last acc let repeat_blocks #a #b #c bs inp f l init = let len = length inp in let nb = len / bs in let rem = len % bs in let acc = repeati nb (repeat_blocks_f bs inp f nb) init in let last = seq_sub inp (nb * bs) rem in l rem last acc let lemma_repeat_blocks #a #b #c bs inp f l init = () let repeat_blocks_multi #a #b bs inp f init = let len = length inp in let nb = len / bs in repeati nb (repeat_blocks_f bs inp f nb) init let lemma_repeat_blocks_multi #a #b bs inp f init = () let generate_blocks_a (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (i:nat{i <= max}) = a i & s:seq t{length s == i * blocklen} let generate_blocks_inner (t:Type) (blocklen:size_nat) (max:nat) (a:(i:nat{i <= max} -> Type)) (f:(i:nat{i < max} -> a i -> a (i + 1) & s:seq t{length s == blocklen})) (i:nat{i < max}) (acc:generate_blocks_a t blocklen max a i) : generate_blocks_a t blocklen max a (i + 1) = let acc, o = acc in let acc', block = f i acc in let o' : s:seq t{length s == ((i + 1) * blocklen)} = Seq.append o block in acc', o' let generate_blocks #t len max n a f acc0 = let a0 = (acc0, (Seq.empty <: s:seq t{length s == 0 * len})) in repeat_gen n (generate_blocks_a t len max a) (generate_blocks_inner t len max a f) a0 let generate_blocks_simple_a (a:Type) (bs:size_nat) (max:nat) (i:nat{i <= max}) = s:seq a{length s == i * bs} let generate_blocks_simple_f (#a:Type) (bs:size_nat{bs > 0}) (max:nat) (f:(i:nat{i < max} -> lseq a bs)) (i:nat{i < max}) (acc:generate_blocks_simple_a a bs max i) : generate_blocks_simple_a a bs max (i + 1) = Seq.append acc (f i) let generate_blocks_simple #a bs max nb f = repeat_gen nb (generate_blocks_simple_a a bs max) (generate_blocks_simple_f #a bs max f) Seq.empty #restart-solver let div_interval b n i = Math.Lemmas.lemma_div_le (n * b) i b; Math.Lemmas.cancel_mul_div n b let mod_interval_lt b n i j = div_interval b n i; div_interval b n j let div_mul_lt b a n = () let mod_div_lt b i j = mod_interval_lt b (j / b) i j let div_mul_l a b c d = calc (==) { a / (c * d); == { } a / (d * c); == { Math.Lemmas.division_multiplication_lemma a d c } (a / d) / c; == { } (b / d) / c; == { Math.Lemmas.division_multiplication_lemma b d c } b / (d * c); == { } b / (c * d); } let map_blocks_multi #a bs max nb inp f = repeat_gen nb (map_blocks_a a bs max) (map_blocks_f #a bs max inp f) Seq.empty let lemma_map_blocks_multi #a bs max nb inp f = () private val mod_prop: n:pos -> a:nat -> b:nat{a * n <= b /\ b < (a + 1) * n} -> Lemma (b - a * n == b % n) let mod_prop n a b = Math.Lemmas.modulo_lemma (b - a * n) n; Math.Lemmas.lemma_mod_sub b n a #push-options "--z3rlimit 200"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.Sequence.fst" }
[ { "abbrev": false, "full_module": "Lib.LoopCombinators", "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": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
bs: Lib.IntTypes.size_pos -> max: Prims.pos -> n: Prims.pos{n <= max} -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp == max * bs} -> f: (i: Prims.nat{i < max} -> _: Lib.Sequence.lseq a bs -> Lib.Sequence.lseq a bs) -> i: Prims.nat{i < n * bs} -> FStar.Pervasives.Lemma (ensures (Lib.Sequence.div_mul_lt bs i n; let j = i / bs in let block = FStar.Seq.Base.slice inp (j * bs) ((j + 1) * bs) in FStar.Seq.Base.index (Lib.Sequence.map_blocks_multi bs max n inp f) i == FStar.Seq.Base.index (f j block) (i % bs)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.size_pos", "Prims.pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.nat", "Prims.op_LessThan", "Lib.Sequence.lseq", "Prims.op_Subtraction", "Lib.Sequence.index_map_blocks_multi", "Prims.unit", "FStar.Seq.Base.lemma_index_app1", "Prims.bool", "Lib.Sequence.mod_prop", "FStar.Seq.Base.lemma_index_app2", "FStar.Seq.Base.slice", "Lib.LoopCombinators.repeat_gen", "Lib.LoopCombinators.unfold_repeat_gen", "FStar.Seq.Base.seq", "Prims.op_Equality", "FStar.Seq.Base.length", "FStar.Seq.Base.empty", "Lib.Sequence.map_blocks_a", "Prims.op_Addition", "Lib.Sequence.map_blocks_f" ]
[ "recursion" ]
false
false
true
false
false
let rec index_map_blocks_multi #a bs max n inp f i =
let map_blocks_a = map_blocks_a a bs max in let map_blocks_f = map_blocks_f #a bs max inp f in let acc0 = Seq.empty #a in let s1 = repeat_gen n map_blocks_a map_blocks_f acc0 in unfold_repeat_gen n map_blocks_a map_blocks_f acc0 (n - 1); let s = repeat_gen (n - 1) map_blocks_a map_blocks_f acc0 in let s' = f (n - 1) (Seq.slice inp ((n - 1) * bs) (n * bs)) in if i < (n - 1) * bs then (Seq.lemma_index_app1 s s' i; index_map_blocks_multi #a bs max (n - 1) inp f i) else (Seq.lemma_index_app2 s s' i; mod_prop bs (n - 1) i)
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.supported_alg
val supported_alg : Type0
let supported_alg = S.supported_alg
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 57, "start_col": 0, "start_line": 57 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.HMAC_DRBG.supported_alg" ]
[]
false
false
false
true
true
let supported_alg =
S.supported_alg
false
OWGCounter.fst
OWGCounter.incr
val incr: r: ref int -> r_mine: ghost_ref int -> r_other: ghost_ref int -> b: G.erased bool -> l: lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) -> n_ghost: G.erased int -> Prims.unit -> SteelT unit (ghost_pts_to r_mine half_perm n_ghost) (fun _ -> ghost_pts_to r_mine half_perm (n_ghost + 1))
val incr: r: ref int -> r_mine: ghost_ref int -> r_other: ghost_ref int -> b: G.erased bool -> l: lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) -> n_ghost: G.erased int -> Prims.unit -> SteelT unit (ghost_pts_to r_mine half_perm n_ghost) (fun _ -> ghost_pts_to r_mine half_perm (n_ghost + 1))
let incr (r:ref int) (r_mine r_other:ghost_ref int) (b:G.erased bool) (l:lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine))) (n_ghost:G.erased int) () : SteelT unit (ghost_pts_to r_mine half_perm n_ghost) (fun _ -> ghost_pts_to r_mine half_perm (n_ghost + 1)) = og_acquire r r_mine r_other b l; let w : G.erased (int & int) = witness_exists () in incr_ctr r; incr_ghost_contrib #n_ghost #(fst w) r_mine; rewrite_slprop (pts_to r full_perm ((fst w + snd w) + 1)) (pts_to r full_perm ((fst w + 1) + snd w)) (fun _ -> ()); intro_exists (fst w + 1, snd w) (lock_inv_pred r r_mine r_other); og_release r r_mine r_other b l
{ "file_name": "share/steel/examples/steel/OWGCounter.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 233, "start_col": 0, "start_line": 217 }
(* Copyright 2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) (* * An implementation of the parallel counter presented by Owicki and Gries * "Verifying properties of parallel programs: An axiomatic approach.", CACM'76 * * In this example, the main thread forks two worker thread that both * increment a shared counter. The goal of the example is to show that * after both the worker threads are done, the value of the counter is * its original value + 2. * * See http://pm.inf.ethz.ch/publications/getpdf.php for an implementation * of the OWG counters in the Chalice framework. *) module OWGCounter module G = FStar.Ghost open Steel.Memory open Steel.FractionalPermission open Steel.Reference open Steel.SpinLock open Steel.Effect.Atomic open Steel.Effect module R = Steel.Reference module P = Steel.FractionalPermission module A = Steel.Effect.Atomic #set-options "--ide_id_info_off --using_facts_from '* -FStar.Tactics -FStar.Reflection' --fuel 0 --ifuel 0" let half_perm = half_perm full_perm (* Some basic wrappers to avoid issues with normalization. TODO: The frame inference tactic should not normalize fst and snd*) noextract let fst = fst noextract let snd = snd /// The core invariant of the Owicki-Gries counter, shared by the two parties. /// The concrete counter [r] is shared, and the full permission is stored in the invariant. /// Each party also has half permission to their own ghost counter [r1] or [r2], ensuring that /// only them can modify it by retrieving the other half of the permission when accessing the invariant. /// The `__reduce__` attribute indicates the frame inference tactic to unfold this predicate for frame inference only [@@ __reduce__] let lock_inv_slprop (r:ref int) (r1 r2:ghost_ref int) (w:int & int) = ghost_pts_to r1 half_perm (fst w) `star` ghost_pts_to r2 half_perm (snd w) `star` pts_to r full_perm (fst w + snd w) [@@ __reduce__] let lock_inv_pred (r:ref int) (r1 r2:ghost_ref int) = fun (x:int & int) -> lock_inv_slprop r r1 r2 x /// The actual invariant, existentially quantifying over the values currently stored in the two ghost references [@@ __reduce__] let lock_inv (r:ref int) (r1 r2:ghost_ref int) : vprop = h_exists (lock_inv_pred r r1 r2) #push-options "--warn_error -271 --fuel 1 --ifuel 1" /// A helper lemma to reason about the lock invariant let lock_inv_equiv_lemma (r:ref int) (r1 r2:ghost_ref int) : Lemma (lock_inv r r1 r2 `equiv` lock_inv r r2 r1) = let aux (r:ref int) (r1 r2:ghost_ref int) (m:mem) : Lemma (requires interp (hp_of (lock_inv r r1 r2)) m) (ensures interp (hp_of (lock_inv r r2 r1)) m) [SMTPat ()] = assert ( Steel.Memory.h_exists #(int & int) (fun x -> hp_of (lock_inv_pred r r1 r2 x)) == h_exists_sl #(int & int) (lock_inv_pred r r1 r2)) by (FStar.Tactics.norm [delta_only [`%h_exists_sl]]); let w : G.erased (int & int) = id_elim_exists (fun x -> hp_of (lock_inv_pred r r1 r2 x)) m in assert ((ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))) `equiv` (ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w)))) by (FStar.Tactics.norm [delta_attr [`%__steel_reduce__]]; canon' false (`true_p) (`true_p)); reveal_equiv (ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))) (ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))); assert (interp (hp_of (lock_inv_pred r r2 r1 (snd w, fst w))) m); intro_h_exists (snd w, fst w) (fun x -> hp_of (lock_inv_pred r r2 r1 x)) m; assert (interp (Steel.Memory.h_exists (fun x -> hp_of (lock_inv_pred r r2 r1 x))) m); assert ( Steel.Memory.h_exists #(int & int) (fun x -> hp_of (lock_inv_pred r r2 r1 x)) == h_exists_sl #(int & int) (lock_inv_pred r r2 r1)) by (FStar.Tactics.norm [delta_only [`%h_exists_sl]]) in reveal_equiv (lock_inv r r1 r2) (lock_inv r r2 r1) #pop-options /// Acquiring the shared lock invariant inline_for_extraction noextract let og_acquire (r:ref int) (r_mine r_other:ghost_ref int) (b:G.erased bool) (l:lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine))) : SteelT unit emp (fun _ -> lock_inv r r_mine r_other) = acquire l; if b then begin rewrite_slprop (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (lock_inv r r_mine r_other) (fun _ -> ()); () end else begin rewrite_slprop (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (lock_inv r r_other r_mine) (fun _ -> ()); lock_inv_equiv_lemma r r_other r_mine; rewrite_slprop (lock_inv r r_other r_mine) (lock_inv r r_mine r_other) (fun _ -> reveal_equiv (lock_inv r r_other r_mine) (lock_inv r r_mine r_other)) end /// Releasing the shared lock invariant inline_for_extraction noextract let og_release (r:ref int) (r_mine r_other:ghost_ref int) (b:G.erased bool) (l:lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine))) : SteelT unit (lock_inv r r_mine r_other) (fun _ -> emp) = if b then begin rewrite_slprop (lock_inv r r_mine r_other) (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (fun _ -> ()); () end else begin lock_inv_equiv_lemma r r_mine r_other; rewrite_slprop (lock_inv r r_mine r_other) (lock_inv r r_other r_mine) (fun _ -> reveal_equiv (lock_inv r r_mine r_other) (lock_inv r r_other r_mine)); rewrite_slprop (lock_inv r r_other r_mine) (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (fun _ -> ()) end; release l inline_for_extraction noextract let incr_ctr (#v:G.erased int) (r:ref int) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm (v+1)) = let n = R.read_pt r in R.write_pt r (n+1); rewrite_slprop (pts_to r full_perm (n + 1)) (pts_to r full_perm (v+1)) (fun _ -> ()) inline_for_extraction noextract let rewrite_perm(#a:Type) (#v:G.erased a) (r:ghost_ref a) (p1 p2:P.perm) : Steel unit (ghost_pts_to r p1 v) (fun _ -> ghost_pts_to r p2 v) (fun _ -> p1 == p2) (fun _ _ _ -> True) = rewrite_slprop (ghost_pts_to r p1 v) (ghost_pts_to r p2 v) (fun _ -> ()) inline_for_extraction noextract let incr_ghost_contrib (#v1 #v2:G.erased int) (r:ghost_ref int) : Steel unit (ghost_pts_to r half_perm v1 `star` ghost_pts_to r half_perm v2) (fun _ -> ghost_pts_to r half_perm (v1+1) `star` ghost_pts_to r half_perm (v2+1)) (fun _ -> True) (fun _ _ _ -> v1 == v2) = ghost_gather_pt #_ #_ #half_perm #half_perm #v1 #v2 r; rewrite_perm r (sum_perm half_perm half_perm) full_perm; ghost_write_pt r (v1+1); ghost_share_pt r; rewrite_slprop (ghost_pts_to r (P.half_perm P.full_perm) (v1+1) `star` ghost_pts_to r (P.half_perm P.full_perm) (v1+1)) (ghost_pts_to r half_perm (v1+1) `star` ghost_pts_to r half_perm (v2+1)) (fun _ -> ())
{ "checked_file": "/", "dependencies": [ "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "OWGCounter.fst" }
[ { "abbrev": true, "full_module": "Steel.Effect.Atomic", "short_module": "A" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.Reference.ref Prims.int -> r_mine: Steel.Reference.ghost_ref Prims.int -> r_other: Steel.Reference.ghost_ref Prims.int -> b: FStar.Ghost.erased Prims.bool -> l: Steel.SpinLock.lock (OWGCounter.lock_inv r (match FStar.Ghost.reveal b with | true -> r_mine | _ -> r_other) (match FStar.Ghost.reveal b with | true -> r_other | _ -> r_mine)) -> n_ghost: FStar.Ghost.erased Prims.int -> _: Prims.unit -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Steel.Reference.ref", "Prims.int", "Steel.Reference.ghost_ref", "FStar.Ghost.erased", "Prims.bool", "Steel.SpinLock.lock", "OWGCounter.lock_inv", "FStar.Ghost.reveal", "Prims.unit", "OWGCounter.og_release", "Steel.Effect.Atomic.intro_exists", "FStar.Pervasives.Native.tuple2", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "OWGCounter.fst", "OWGCounter.snd", "OWGCounter.lock_inv_pred", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.Memory.mem", "OWGCounter.incr_ghost_contrib", "OWGCounter.incr_ctr", "Steel.Effect.Atomic.witness_exists", "Steel.Effect.Common.VStar", "Steel.Reference.ghost_pts_to", "OWGCounter.half_perm", "Steel.Effect.Common.vprop", "OWGCounter.og_acquire" ]
[]
false
true
false
false
false
let incr (r: ref int) (r_mine: ghost_ref int) (r_other: ghost_ref int) (b: G.erased bool) (l: lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine))) (n_ghost: G.erased int) () : SteelT unit (ghost_pts_to r_mine half_perm n_ghost) (fun _ -> ghost_pts_to r_mine half_perm (n_ghost + 1)) =
og_acquire r r_mine r_other b l; let w:G.erased (int & int) = witness_exists () in incr_ctr r; incr_ghost_contrib #n_ghost #(fst w) r_mine; rewrite_slprop (pts_to r full_perm ((fst w + snd w) + 1)) (pts_to r full_perm ((fst w + 1) + snd w)) (fun _ -> ()); intro_exists (fst w + 1, snd w) (lock_inv_pred r r_mine r_other); og_release r r_mine r_other b l
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.disjoint_st
val disjoint_st : st: Hacl.HMAC_DRBG.state a -> b: Lib.Buffer.buffer Lib.IntTypes.uint8 -> Type0
let disjoint_st (#a:supported_alg) (st:state a) (b:buffer uint8) = B.loc_disjoint (footprint st) (B.loc_buffer b)
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 100, "start_col": 0, "start_line": 99 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) [@@ Comment "Return the minimal entropy input length of the desired hash function. @param a Hash algorithm to use."] let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) val state: supported_alg -> Type0 inline_for_extraction noextract val freeable: #a:supported_alg -> st:state a -> Type0 val footprint: #a:supported_alg -> st:state a -> GTot B.loc inline_for_extraction noextract val invariant: #a:supported_alg -> st:state a -> h:HS.mem -> Type0
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
st: Hacl.HMAC_DRBG.state a -> b: Lib.Buffer.buffer Lib.IntTypes.uint8 -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.HMAC_DRBG.supported_alg", "Hacl.HMAC_DRBG.state", "Lib.Buffer.buffer", "Lib.IntTypes.uint8", "LowStar.Monotonic.Buffer.loc_disjoint", "Hacl.HMAC_DRBG.footprint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder" ]
[]
false
false
false
false
true
let disjoint_st (#a: supported_alg) (st: state a) (b: buffer uint8) =
B.loc_disjoint (footprint st) (B.loc_buffer b)
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.reseed_interval
val reseed_interval:n: size_t{v n == S.reseed_interval}
val reseed_interval:n: size_t{v n == S.reseed_interval}
let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval)
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 61, "start_col": 0, "start_line": 59 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v n == Spec.HMAC_DRBG.reseed_interval}
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.normalize_term", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Spec.HMAC_DRBG.reseed_interval", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.pow2" ]
[]
false
false
false
false
false
let reseed_interval:n: size_t{v n == S.reseed_interval} =
assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval)
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.max_length
val max_length:n: size_t{v n == S.max_length}
val max_length:n: size_t{v n == S.max_length}
let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length)
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 69, "start_col": 0, "start_line": 67 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length)
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v n == Spec.HMAC_DRBG.max_length}
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.normalize_term", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Spec.HMAC_DRBG.max_length", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.pow2" ]
[]
false
false
false
false
false
let max_length:n: size_t{v n == S.max_length} =
assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length)
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.max_personalization_string_length
val max_personalization_string_length:n: size_t{v n == S.max_personalization_string_length}
val max_personalization_string_length:n: size_t{v n == S.max_personalization_string_length}
let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length)
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 73, "start_col": 0, "start_line": 71 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length)
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v n == Spec.HMAC_DRBG.max_personalization_string_length}
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.normalize_term", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Spec.HMAC_DRBG.max_personalization_string_length", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.pow2" ]
[]
false
false
false
false
false
let max_personalization_string_length:n: size_t{v n == S.max_personalization_string_length} =
assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length)
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.inspect_universe
val inspect_universe (u:universe) : Tot named_universe_view
val inspect_universe (u:universe) : Tot named_universe_view
let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 45, "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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
u474: FStar.Tactics.NamedView.universe -> FStar.Tactics.NamedView.named_universe_view
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.universe", "FStar.Tactics.NamedView.open_universe_view", "FStar.Stubs.Reflection.V2.Data.universe_view", "Prims.precedes", "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.V2.Builtins.inspect_universe", "FStar.Tactics.NamedView.named_universe_view" ]
[]
false
false
false
true
false
let inspect_universe (u: universe) : named_universe_view =
let v = R.inspect_universe u in open_universe_view v
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.max_additional_input_length
val max_additional_input_length:n: size_t{v n == S.max_additional_input_length}
val max_additional_input_length:n: size_t{v n == S.max_additional_input_length}
let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length)
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 77, "start_col": 0, "start_line": 75 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length)
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v n == Spec.HMAC_DRBG.max_additional_input_length}
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.normalize_term", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Spec.HMAC_DRBG.max_additional_input_length", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.pow2" ]
[]
false
false
false
false
false
let max_additional_input_length:n: size_t{v n == S.max_additional_input_length} =
assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length)
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.pack_universe
val pack_universe (uv:named_universe_view) : Tot universe
val pack_universe (uv:named_universe_view) : Tot universe
let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 59, "start_col": 0, "start_line": 57 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
uv: FStar.Tactics.NamedView.named_universe_view -> FStar.Tactics.NamedView.universe
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.named_universe_view", "FStar.Stubs.Reflection.V2.Builtins.pack_universe", "FStar.Stubs.Reflection.V2.Data.universe_view", "FStar.Tactics.NamedView.close_universe_view", "FStar.Tactics.NamedView.universe" ]
[]
false
false
false
true
false
let pack_universe (uv: named_universe_view) : universe =
let uv = close_universe_view uv in R.pack_universe uv
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.__binding_to_binder
val __binding_to_binder (bnd: binding) (b: R.binder) : binder
val __binding_to_binder (bnd: binding) (b: R.binder) : binder
let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; }
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 69, "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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
bnd: FStar.Tactics.NamedView.binding -> b: FStar.Stubs.Reflection.Types.binder -> FStar.Tactics.NamedView.binder
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.binding", "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.NamedView.Mkbinder", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__uniq", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__ppname", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__sort", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__qual", "FStar.Stubs.Reflection.V2.Builtins.inspect_binder", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs", "FStar.Tactics.NamedView.binder" ]
[]
false
false
false
true
false
let __binding_to_binder (bnd: binding) (b: R.binder) : binder =
{ ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs }
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.r_binder_to_namedv
val r_binder_to_namedv (b: binder) : R.namedv
val r_binder_to_namedv (b: binder) : R.namedv
let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; }
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 77, "start_col": 0, "start_line": 72 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Tactics.NamedView.binder -> FStar.Stubs.Reflection.Types.namedv
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.binder", "FStar.Stubs.Reflection.V2.Builtins.pack_namedv", "FStar.Stubs.Reflection.V2.Data.Mknamedv_view", "FStar.Tactics.NamedView.__proj__Mkbinder__item__uniq", "FStar.Sealed.seal", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.__proj__Mkbinder__item__sort", "FStar.Tactics.NamedView.__proj__Mkbinder__item__ppname", "FStar.Stubs.Reflection.Types.namedv" ]
[]
false
false
false
true
false
let r_binder_to_namedv (b: binder) : R.namedv =
pack_namedv ({ uniq = b.uniq; sort = seal b.sort; ppname = b.ppname })
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.free_st
val free_st : a: Hacl.HMAC_DRBG.supported_alg -> Type0
let free_st (a: supported_alg) = s:state a -> ST unit (requires fun h0 -> freeable s /\ invariant s h0) (ensures fun h0 _ h1 -> B.(modifies (footprint s) h0 h1))
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 37, "end_line": 253, "start_col": 0, "start_line": 247 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) [@@ Comment "Return the minimal entropy input length of the desired hash function. @param a Hash algorithm to use."] let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) val state: supported_alg -> Type0 inline_for_extraction noextract val freeable: #a:supported_alg -> st:state a -> Type0 val footprint: #a:supported_alg -> st:state a -> GTot B.loc inline_for_extraction noextract val invariant: #a:supported_alg -> st:state a -> h:HS.mem -> Type0 inline_for_extraction noextract let disjoint_st (#a:supported_alg) (st:state a) (b:buffer uint8) = B.loc_disjoint (footprint st) (B.loc_buffer b) val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) inline_for_extraction noextract val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st)) /\ invariant st h1) [@@ Comment "Create a DRBG state. @param a Hash algorithm to use. The possible instantiations are ... * `Spec_Hash_Definitions_SHA2_256`, * `Spec_Hash_Definitions_SHA2_384`, * `Spec_Hash_Definitions_SHA2_512`, and * `Spec_Hash_Definitions_SHA1`."] inline_for_extraction val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st) h0 h1 /\ B.(loc_includes (loc_region_only true r)) (footprint st) /\ invariant st h1 /\ freeable st) inline_for_extraction noextract let instantiate_st (a:supported_alg) = st:state a -> entropy_input_len:size_t -> entropy_input:lbuffer uint8 entropy_input_len -> nonce_len:size_t -> nonce:lbuffer uint8 nonce_len -> personalization_string_len:size_t -> personalization_string:lbuffer uint8 personalization_string_len -> Stack unit (requires fun h0 -> live h0 entropy_input /\ live h0 nonce /\ live h0 personalization_string /\ invariant st h0 /\ S.min_length a <= v entropy_input_len /\ v entropy_input_len <= v max_length /\ S.min_length a / 2 <= v nonce_len /\ v nonce_len <= v max_length /\ v personalization_string_len <= S.max_personalization_string_length) (ensures fun h0 _ h1 -> S.hmac_input_bound a; invariant st h1 /\ B.modifies (footprint st) h0 h1 /\ repr st h1 == S.instantiate (as_seq h0 entropy_input) (as_seq h0 nonce) (as_seq h0 personalization_string)) inline_for_extraction noextract val mk_instantiate: #a:supported_alg -> hmac:HMAC.compute_st a -> instantiate_st a [@@ Comment "Instantiate the DRBG. @param a Hash algorithm to use. (Value must match the value used in `Hacl_HMAC_DRBG_create_in`.) @param st Pointer to DRBG state. @param entropy_input_len Length of entropy input. @param entropy_input Pointer to `entropy_input_len` bytes of memory where entropy input is read from. @param nonce_len Length of nonce. @param nonce Pointer to `nonce_len` bytes of memory where nonce is read from. @param personalization_string_len length of personalization string. @param personalization_string Pointer to `personalization_string_len` bytes of memory where personalization string is read from."] val instantiate: a:supported_alg -> instantiate_st a inline_for_extraction noextract let reseed_st (a:supported_alg) = st:state a -> entropy_input_len:size_t -> entropy_input:lbuffer uint8 entropy_input_len -> additional_input_len:size_t -> additional_input:lbuffer uint8 additional_input_len -> Stack unit (requires fun h0 -> invariant st h0 /\ live h0 entropy_input /\ live h0 additional_input /\ disjoint_st st entropy_input /\ disjoint_st st additional_input /\ S.min_length a <= v entropy_input_len /\ v entropy_input_len <= v max_length /\ v additional_input_len <= S.max_additional_input_length) (ensures fun h0 _ h1 -> S.hmac_input_bound a; invariant st h1 /\ B.modifies (footprint st) h0 h1 /\ repr st h1 == S.reseed (repr st h0) (as_seq h0 entropy_input) (as_seq h0 additional_input)) inline_for_extraction noextract val mk_reseed: #a:supported_alg -> hmac:HMAC.compute_st a -> reseed_st a [@@ Comment "Reseed the DRBG. @param a Hash algorithm to use. (Value must match the value used in `Hacl_HMAC_DRBG_create_in`.) @param st Pointer to DRBG state. @param entropy_input_len Length of entropy input. @param entropy_input Pointer to `entropy_input_len` bytes of memory where entropy input is read from. @param additional_input_input_len Length of additional input. @param additional_input_input Pointer to `additional_input_input_len` bytes of memory where additional input is read from."] val reseed: a:supported_alg -> reseed_st a inline_for_extraction noextract let generate_st (a:supported_alg) = output:buffer uint8 -> st:state a -> n:size_t -> additional_input_len:size_t -> additional_input:lbuffer uint8 additional_input_len -> Stack bool (requires fun h0 -> live h0 output /\ invariant st h0 /\ live h0 additional_input /\ disjoint_st st output /\ disjoint_st st additional_input /\ disjoint output additional_input /\ v n = length output /\ v n <= S.max_output_length /\ v additional_input_len <= S.max_additional_input_length) (ensures fun h0 b h1 -> S.hmac_input_bound a; match S.generate (repr st h0) (v n) (as_seq h0 additional_input) with | None -> b = false /\ invariant st h1 /\ modifies0 h0 h1 | Some (out, st_) -> b = true /\ invariant st h1 /\ B.modifies (loc output |+| footprint st) h0 h1 /\ repr st h1 == st_ /\ as_seq #MUT #_ #n h1 output == out) inline_for_extraction noextract val mk_generate: #a:supported_alg -> HMAC.compute_st a -> generate_st a [@@ Comment "Generate output. @param a Hash algorithm to use. (Value must match the value used in `create_in`.) @param output Pointer to `n` bytes of memory where random output is written to. @param st Pointer to DRBG state. @param n Length of desired output. @param additional_input_input_len Length of additional input. @param additional_input_input Pointer to `additional_input_input_len` bytes of memory where additional input is read from."] val generate: a:supported_alg -> generate_st a
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.HMAC_DRBG.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.HMAC_DRBG.supported_alg", "Hacl.HMAC_DRBG.state", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Hacl.HMAC_DRBG.freeable", "Hacl.HMAC_DRBG.invariant", "LowStar.Monotonic.Buffer.modifies", "Hacl.HMAC_DRBG.footprint" ]
[]
false
false
false
true
true
let free_st (a: supported_alg) =
s: state a -> ST unit (requires fun h0 -> freeable s /\ invariant s h0) (ensures fun h0 _ h1 -> let open B in modifies (footprint s) h0 h1)
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_binder
val open_binder (b: R.binder) : Tac binder
val open_binder (b: R.binder) : Tac binder
let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; }
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 89, "start_col": 0, "start_line": 80 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Stubs.Reflection.Types.binder -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binder
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.NamedView.Mkbinder", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__ppname", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__sort", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__qual", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs", "FStar.Stubs.Reflection.V2.Data.binder_view", "Prims.precedes", "FStar.Stubs.Reflection.V2.Builtins.inspect_binder", "FStar.Tactics.NamedView.binder", "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.fresh" ]
[]
false
true
false
false
false
let open_binder (b: R.binder) : Tac binder =
let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs }
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.max_output_length
val max_output_length:n: size_t{v n == S.max_output_length}
val max_output_length:n: size_t{v n == S.max_output_length}
let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length)
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 65, "start_col": 0, "start_line": 63 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval)
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v n == Spec.HMAC_DRBG.max_output_length}
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.normalize_term", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Spec.HMAC_DRBG.max_output_length", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.pow2" ]
[]
false
false
false
false
false
let max_output_length:n: size_t{v n == S.max_output_length} =
assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length)
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_term_with
val open_term_with (b: R.binder) (nb: binder) (t: term) : Tac term
val open_term_with (b: R.binder) (nb: binder) (t: term) : Tac term
let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t'
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 109, "start_col": 0, "start_line": 101 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Stubs.Reflection.Types.binder -> nb: FStar.Tactics.NamedView.binder -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.term", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Stubs.Syntax.Syntax.DB", "Prims.Nil", "FStar.Stubs.Reflection.Types.namedv", "FStar.Stubs.Reflection.V2.Builtins.pack_namedv", "FStar.Stubs.Reflection.V2.Data.Mknamedv_view", "FStar.Tactics.NamedView.__proj__Mkbinder__item__uniq", "FStar.Sealed.seal", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.__proj__Mkbinder__item__sort", "FStar.Tactics.NamedView.__proj__Mkbinder__item__ppname" ]
[]
false
true
false
false
false
let open_term_with (b: R.binder) (nb: binder) (t: term) : Tac term =
let nv:R.namedv = pack_namedv ({ uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname }) in let t' = subst_term [DB 0 nv] t in t'
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_universe_view
val open_universe_view (v: RD.universe_view) : named_universe_view
val open_universe_view (v: RD.universe_view) : named_universe_view
let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 41, "start_col": 0, "start_line": 33 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Stubs.Reflection.V2.Data.universe_view -> FStar.Tactics.NamedView.named_universe_view
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.V2.Data.universe_view", "FStar.Tactics.NamedView.Uv_Zero", "FStar.Stubs.Reflection.Types.universe", "FStar.Tactics.NamedView.Uv_Succ", "FStar.Stubs.Reflection.V2.Data.universes", "FStar.Tactics.NamedView.Uv_Max", "Prims.nat", "FStar.Tactics.NamedView.Uv_BVar", "FStar.Stubs.Reflection.Types.univ_name", "FStar.Tactics.NamedView.Uv_Name", "FStar.Stubs.Reflection.V2.Builtins.inspect_ident", "FStar.Stubs.Reflection.Types.universe_uvar", "FStar.Tactics.NamedView.Uv_Unif", "FStar.Tactics.NamedView.Uv_Unk", "FStar.Tactics.NamedView.named_universe_view" ]
[]
false
false
false
true
false
let open_universe_view (v: RD.universe_view) : named_universe_view =
match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_term
val open_term (b: R.binder) (t: term) : Tac (binder & term)
val open_term (b: R.binder) (t: term) : Tac (binder & term)
let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t)
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 114, "start_col": 0, "start_line": 112 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Stubs.Reflection.Types.binder -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac (FStar.Tactics.NamedView.binder * FStar.Tactics.NamedView.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.NamedView.term", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.NamedView.binder", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.NamedView.open_term_with", "FStar.Tactics.NamedView.open_binder" ]
[]
false
true
false
false
false
let open_term (b: R.binder) (t: term) : Tac (binder & term) =
let bndr:binder = open_binder b in (bndr, open_term_with b bndr t)
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_binder
val close_binder (b: binder) : R.binder
val close_binder (b: binder) : R.binder
let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; }
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 98, "start_col": 0, "start_line": 92 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Tactics.NamedView.binder -> FStar.Stubs.Reflection.Types.binder
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.binder", "FStar.Stubs.Reflection.V2.Builtins.pack_binder", "FStar.Stubs.Reflection.V2.Data.Mkbinder_view", "FStar.Tactics.NamedView.__proj__Mkbinder__item__sort", "FStar.Tactics.NamedView.__proj__Mkbinder__item__qual", "FStar.Tactics.NamedView.__proj__Mkbinder__item__attrs", "FStar.Tactics.NamedView.__proj__Mkbinder__item__ppname", "FStar.Stubs.Reflection.Types.binder" ]
[]
false
false
false
true
false
let close_binder (b: binder) : R.binder =
pack_binder ({ sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs })
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.subst_comp
val subst_comp (s: subst_t) (c: comp) : comp
val subst_comp (s: subst_t) (c: comp) : comp
let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c))
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 45, "end_line": 117, "start_col": 0, "start_line": 116 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Stubs.Syntax.Syntax.subst_t -> c: FStar.Tactics.NamedView.comp -> FStar.Tactics.NamedView.comp
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Tactics.NamedView.comp", "FStar.Stubs.Reflection.V2.Builtins.inspect_comp", "FStar.Stubs.Reflection.V2.Builtins.subst_comp", "FStar.Stubs.Reflection.V2.Builtins.pack_comp" ]
[]
false
false
false
true
false
let subst_comp (s: subst_t) (c: comp) : comp =
inspect_comp (R.subst_comp s (pack_comp c))
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_comp
val open_comp (b: R.binder) (t: comp) : Tac (binder & comp)
val open_comp (b: R.binder) (t: comp) : Tac (binder & comp)
let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 138, "start_col": 0, "start_line": 120 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Stubs.Reflection.Types.binder -> t: FStar.Tactics.NamedView.comp -> FStar.Tactics.Effect.Tac (FStar.Tactics.NamedView.binder * FStar.Tactics.NamedView.comp)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.NamedView.comp", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.Mkbinder", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__ppname", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__sort", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__qual", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs", "FStar.Tactics.NamedView.subst_comp", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Stubs.Syntax.Syntax.DB", "Prims.Nil", "FStar.Stubs.Reflection.Types.namedv", "FStar.Stubs.Reflection.V2.Builtins.pack_namedv", "FStar.Stubs.Reflection.V2.Data.Mknamedv_view", "FStar.Sealed.seal", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Reflection.V2.Data.binder_view", "FStar.Stubs.Reflection.V2.Builtins.inspect_binder", "FStar.Pervasives.Native.tuple2", "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.fresh" ]
[]
false
true
false
false
false
let open_comp (b: R.binder) (t: comp) : Tac (binder & comp) =
let n = fresh () in let bv:binder_view = inspect_binder b in let nv:R.namedv = pack_namedv ({ uniq = n; sort = seal bv.sort; ppname = bv.ppname }) in let t' = subst_comp [DB 0 nv] t in let bndr:binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs } in (bndr, t')
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_term
val close_term (b:binder) (t:term) : Tot (R.binder & term)
val close_term (b:binder) (t:term) : Tot (R.binder & term)
let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 200, "start_col": 0, "start_line": 196 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Tactics.NamedView.binder -> t: FStar.Tactics.NamedView.term -> FStar.Stubs.Reflection.Types.binder * FStar.Tactics.NamedView.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.term", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.Types.binder", "FStar.Stubs.Reflection.V2.Builtins.pack_binder", "FStar.Stubs.Reflection.V2.Data.Mkbinder_view", "FStar.Tactics.NamedView.__proj__Mkbinder__item__sort", "FStar.Tactics.NamedView.__proj__Mkbinder__item__qual", "FStar.Tactics.NamedView.__proj__Mkbinder__item__attrs", "FStar.Tactics.NamedView.__proj__Mkbinder__item__ppname", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Stubs.Syntax.Syntax.NM", "Prims.Nil", "FStar.Stubs.Reflection.Types.namedv", "FStar.Tactics.NamedView.r_binder_to_namedv", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
true
false
let close_term (b: binder) (t: term) : R.binder & term =
let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder ({ sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs }) in (b, t')
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.min_length
val min_length (a: supported_alg) : n: size_t{v n == S.min_length a}
val min_length (a: supported_alg) : n: size_t{v n == S.min_length a}
let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256))
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 85, "end_line": 86, "start_col": 0, "start_line": 82 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) [@@ Comment "Return the minimal entropy input length of the desired hash function.
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.HMAC_DRBG.supported_alg -> n: Lib.IntTypes.size_t{Lib.IntTypes.v n == Spec.HMAC_DRBG.min_length a}
Prims.Tot
[ "total" ]
[]
[ "Hacl.HMAC_DRBG.supported_alg", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_t", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Spec.HMAC_DRBG.min_length", "Lib.IntTypes.mk_int", "Spec.Hash.Definitions.SHA1", "Spec.Hash.Definitions.SHA2_256", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2" ]
[]
false
false
false
false
false
let min_length (a: supported_alg) : n: size_t{v n == S.min_length a} =
assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256))
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_comp
val close_comp (b: binder) (t: comp) : R.binder & comp
val close_comp (b: binder) (t: comp) : R.binder & comp
let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 206, "start_col": 0, "start_line": 202 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Tactics.NamedView.binder -> t: FStar.Tactics.NamedView.comp -> FStar.Stubs.Reflection.Types.binder * FStar.Tactics.NamedView.comp
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.comp", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.Types.binder", "FStar.Stubs.Reflection.V2.Builtins.pack_binder", "FStar.Stubs.Reflection.V2.Data.Mkbinder_view", "FStar.Tactics.NamedView.__proj__Mkbinder__item__sort", "FStar.Tactics.NamedView.__proj__Mkbinder__item__qual", "FStar.Tactics.NamedView.__proj__Mkbinder__item__attrs", "FStar.Tactics.NamedView.__proj__Mkbinder__item__ppname", "FStar.Tactics.NamedView.subst_comp", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Stubs.Syntax.Syntax.NM", "Prims.Nil", "FStar.Stubs.Reflection.Types.namedv", "FStar.Tactics.NamedView.r_binder_to_namedv", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
true
false
let close_comp (b: binder) (t: comp) : R.binder & comp =
let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder ({ sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs }) in (b, t')
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_comp_with
val open_comp_with (b: R.binder) (nb: binder) (c: comp) : Tac comp
val open_comp_with (b: R.binder) (nb: binder) (c: comp) : Tac comp
let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t'
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 149, "start_col": 0, "start_line": 141 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Stubs.Reflection.Types.binder -> nb: FStar.Tactics.NamedView.binder -> c: FStar.Tactics.NamedView.comp -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.comp
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.comp", "FStar.Tactics.NamedView.subst_comp", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Stubs.Syntax.Syntax.DB", "Prims.Nil", "FStar.Stubs.Reflection.Types.namedv", "FStar.Stubs.Reflection.V2.Builtins.pack_namedv", "FStar.Stubs.Reflection.V2.Data.Mknamedv_view", "FStar.Tactics.NamedView.__proj__Mkbinder__item__uniq", "FStar.Sealed.seal", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.__proj__Mkbinder__item__sort", "FStar.Tactics.NamedView.__proj__Mkbinder__item__ppname" ]
[]
false
true
false
false
false
let open_comp_with (b: R.binder) (nb: binder) (c: comp) : Tac comp =
let nv:R.namedv = pack_namedv ({ uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname }) in let t' = subst_comp [DB 0 nv] c in t'
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.r_subst_binder_sort
val r_subst_binder_sort (s: subst_t) (b: R.binder) : R.binder
val r_subst_binder_sort (s: subst_t) (b: R.binder) : R.binder
let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 229, "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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Stubs.Syntax.Syntax.subst_t -> b: FStar.Stubs.Reflection.Types.binder -> FStar.Stubs.Reflection.Types.binder
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Stubs.Reflection.Types.binder", "FStar.Stubs.Reflection.V2.Builtins.pack_binder", "FStar.Stubs.Reflection.V2.Data.binder_view", "FStar.Stubs.Reflection.V2.Data.Mkbinder_view", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__sort", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__qual", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__ppname", "Prims.precedes", "FStar.Stubs.Reflection.V2.Builtins.inspect_binder" ]
[]
false
false
false
true
false
let r_subst_binder_sort (s: subst_t) (b: R.binder) : R.binder =
let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.subst_binder_sort
val subst_binder_sort (s: subst_t) (b: binder) : binder
val subst_binder_sort (s: subst_t) (b: binder) : binder
let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort }
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 39, "end_line": 232, "start_col": 0, "start_line": 231 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Stubs.Syntax.Syntax.subst_t -> b: FStar.Tactics.NamedView.binder -> FStar.Tactics.NamedView.binder
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.Mkbinder", "FStar.Tactics.NamedView.__proj__Mkbinder__item__uniq", "FStar.Tactics.NamedView.__proj__Mkbinder__item__ppname", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "FStar.Tactics.NamedView.__proj__Mkbinder__item__sort", "FStar.Tactics.NamedView.__proj__Mkbinder__item__qual", "FStar.Tactics.NamedView.__proj__Mkbinder__item__attrs" ]
[]
false
false
false
true
false
let subst_binder_sort (s: subst_t) (b: binder) : binder =
{ b with sort = subst_term s b.sort }
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_term_n
val open_term_n (bs: list R.binder) (t: term) : Tac (list binder & term)
val open_term_n (bs: list R.binder) (t: term) : Tac (list binder & term)
let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 248, "start_col": 0, "start_line": 246 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
bs: Prims.list FStar.Stubs.Reflection.Types.binder -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binder * FStar.Tactics.NamedView.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.binder", "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Pervasives.Native.Mktuple2", "FStar.List.Tot.Base.rev", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.NamedView.__open_term_n_aux", "Prims.Nil", "FStar.Stubs.Syntax.Syntax.subst_elt" ]
[]
false
true
false
false
false
let open_term_n (bs: list R.binder) (t: term) : Tac (list binder & term) =
let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_universe_view
val close_universe_view (v: named_universe_view) : R.universe_view
val close_universe_view (v: named_universe_view) : R.universe_view
let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 55, "start_col": 0, "start_line": 47 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Tactics.NamedView.named_universe_view -> FStar.Stubs.Reflection.V2.Data.universe_view
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.named_universe_view", "FStar.Stubs.Reflection.V2.Data.Uv_Zero", "FStar.Tactics.NamedView.universe", "FStar.Stubs.Reflection.V2.Data.Uv_Succ", "FStar.Stubs.Reflection.V2.Data.universes", "FStar.Stubs.Reflection.V2.Data.Uv_Max", "Prims.nat", "FStar.Stubs.Reflection.V2.Data.Uv_BVar", "FStar.Tactics.NamedView.univ_name", "FStar.Stubs.Reflection.V2.Data.Uv_Name", "FStar.Stubs.Reflection.V2.Builtins.pack_ident", "FStar.Stubs.Reflection.Types.universe_uvar", "FStar.Stubs.Reflection.V2.Data.Uv_Unif", "FStar.Stubs.Reflection.V2.Data.Uv_Unk", "FStar.Stubs.Reflection.V2.Data.universe_view" ]
[]
false
false
false
true
false
let close_universe_view (v: named_universe_view) : R.universe_view =
match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_term_n_with
val open_term_n_with (bs: list R.binder) (nbs: list binder) (t: term) : Tac term
val open_term_n_with (bs: list R.binder) (nbs: list binder) (t: term) : Tac term
let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 258, "start_col": 0, "start_line": 251 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
bs: Prims.list FStar.Stubs.Reflection.Types.binder -> nbs: Prims.list FStar.Tactics.NamedView.binder -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.term", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.NamedView.open_term_with", "FStar.Tactics.NamedView.open_term_n_with", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.Effect.raise", "FStar.Tactics.NamedView.LengthMismatch" ]
[ "recursion" ]
false
true
false
false
false
let rec open_term_n_with (bs: list R.binder) (nbs: list binder) (t: term) : Tac term =
match bs, nbs with | [], [] -> t | b :: bs, nb :: nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_branch
val open_branch (b: R.branch) : Tac branch
val open_branch (b: R.branch) : Tac branch
let open_branch (b : R.branch) : Tac branch = let (pat, t) = b in let pat, s = open_pat pat [] in let t' = subst_term s t in (pat, t')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 331, "start_col": 0, "start_line": 327 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t private let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'') private let rec close_term_n_simple (bs : list simple_binder) (t : term) : list R.simple_binder & term = match bs with | [] -> ([], t) | b::bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b'::bs', t'') private let rec open_pat (p : R.pattern) (s : subst_t) : Tac (pattern & subst_t) = match p with | R.Pat_Constant c -> Pat_Constant {c=c}, s | R.Pat_Var ssort n -> let sort = unseal ssort in let sort = subst_term s sort in let nvv : namedv = { uniq = fresh(); sort = seal sort; ppname = n; } in let nv = pack_namedv nvv in Pat_Var {v=nvv; sort=seal sort}, (DB 0 nv) :: shift_subst 1 s | R.Pat_Cons head univs subpats -> let subpats, s = fold_left (fun (pats,s) (pat,b) -> let pat, s' = open_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in Pat_Cons {head=head; univs=univs; subpats=subpats}, s | R.Pat_Dot_Term None -> Pat_Dot_Term {t=None}, s | R.Pat_Dot_Term (Some t) -> let t = subst_term s t in Pat_Dot_Term {t=Some t}, s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Stubs.Reflection.V2.Data.branch -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.branch
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.V2.Data.branch", "FStar.Stubs.Reflection.V2.Data.pattern", "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.NamedView.pattern", "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.NamedView.term", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "FStar.Tactics.NamedView.branch", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.NamedView.open_pat", "Prims.Nil", "FStar.Stubs.Syntax.Syntax.subst_elt" ]
[]
false
true
false
false
false
let open_branch (b: R.branch) : Tac branch =
let pat, t = b in let pat, s = open_pat pat [] in let t' = subst_term s t in (pat, t')
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.instantiate_st
val instantiate_st : a: Hacl.HMAC_DRBG.supported_alg -> Type0
let instantiate_st (a:supported_alg) = st:state a -> entropy_input_len:size_t -> entropy_input:lbuffer uint8 entropy_input_len -> nonce_len:size_t -> nonce:lbuffer uint8 nonce_len -> personalization_string_len:size_t -> personalization_string:lbuffer uint8 personalization_string_len -> Stack unit (requires fun h0 -> live h0 entropy_input /\ live h0 nonce /\ live h0 personalization_string /\ invariant st h0 /\ S.min_length a <= v entropy_input_len /\ v entropy_input_len <= v max_length /\ S.min_length a / 2 <= v nonce_len /\ v nonce_len <= v max_length /\ v personalization_string_len <= S.max_personalization_string_length) (ensures fun h0 _ h1 -> S.hmac_input_bound a; invariant st h1 /\ B.modifies (footprint st) h0 h1 /\ repr st h1 == S.instantiate (as_seq h0 entropy_input) (as_seq h0 nonce) (as_seq h0 personalization_string))
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 154, "start_col": 0, "start_line": 131 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) [@@ Comment "Return the minimal entropy input length of the desired hash function. @param a Hash algorithm to use."] let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) val state: supported_alg -> Type0 inline_for_extraction noextract val freeable: #a:supported_alg -> st:state a -> Type0 val footprint: #a:supported_alg -> st:state a -> GTot B.loc inline_for_extraction noextract val invariant: #a:supported_alg -> st:state a -> h:HS.mem -> Type0 inline_for_extraction noextract let disjoint_st (#a:supported_alg) (st:state a) (b:buffer uint8) = B.loc_disjoint (footprint st) (B.loc_buffer b) val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) inline_for_extraction noextract val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st)) /\ invariant st h1) [@@ Comment "Create a DRBG state. @param a Hash algorithm to use. The possible instantiations are ... * `Spec_Hash_Definitions_SHA2_256`, * `Spec_Hash_Definitions_SHA2_384`, * `Spec_Hash_Definitions_SHA2_512`, and * `Spec_Hash_Definitions_SHA1`."] inline_for_extraction val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st) h0 h1 /\ B.(loc_includes (loc_region_only true r)) (footprint st) /\ invariant st h1 /\ freeable st)
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.HMAC_DRBG.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.HMAC_DRBG.supported_alg", "Hacl.HMAC_DRBG.state", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.HMAC_DRBG.invariant", "Prims.b2t", "Prims.op_LessThanOrEqual", "Spec.HMAC_DRBG.min_length", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.HMAC_DRBG.max_length", "Prims.op_Division", "Spec.HMAC_DRBG.max_personalization_string_length", "LowStar.Monotonic.Buffer.modifies", "Hacl.HMAC_DRBG.footprint", "Prims.eq2", "Spec.HMAC_DRBG.state", "Hacl.HMAC_DRBG.repr", "Spec.HMAC_DRBG.instantiate", "Lib.Buffer.as_seq", "Spec.HMAC_DRBG.hmac_input_bound" ]
[]
false
false
false
true
true
let instantiate_st (a: supported_alg) =
st: state a -> entropy_input_len: size_t -> entropy_input: lbuffer uint8 entropy_input_len -> nonce_len: size_t -> nonce: lbuffer uint8 nonce_len -> personalization_string_len: size_t -> personalization_string: lbuffer uint8 personalization_string_len -> Stack unit (requires fun h0 -> live h0 entropy_input /\ live h0 nonce /\ live h0 personalization_string /\ invariant st h0 /\ S.min_length a <= v entropy_input_len /\ v entropy_input_len <= v max_length /\ S.min_length a / 2 <= v nonce_len /\ v nonce_len <= v max_length /\ v personalization_string_len <= S.max_personalization_string_length) (ensures fun h0 _ h1 -> S.hmac_input_bound a; invariant st h1 /\ B.modifies (footprint st) h0 h1 /\ repr st h1 == S.instantiate (as_seq h0 entropy_input) (as_seq h0 nonce) (as_seq h0 personalization_string))
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_term_simple
val open_term_simple (b: R.simple_binder) (t: term) : Tac (simple_binder & term)
val open_term_simple (b: R.simple_binder) (t: term) : Tac (simple_binder & term)
let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 172, "start_col": 0, "start_line": 154 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Stubs.Reflection.V2.Data.simple_binder -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac (FStar.Tactics.NamedView.simple_binder * FStar.Tactics.NamedView.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.V2.Data.simple_binder", "FStar.Tactics.NamedView.term", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.NamedView.simple_binder", "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.Mkbinder", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__ppname", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__sort", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__qual", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Stubs.Syntax.Syntax.DB", "Prims.Nil", "FStar.Stubs.Reflection.Types.namedv", "FStar.Stubs.Reflection.V2.Builtins.pack_namedv", "FStar.Stubs.Reflection.V2.Data.Mknamedv_view", "FStar.Sealed.seal", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Reflection.V2.Data.binder_view", "FStar.Stubs.Reflection.V2.Builtins.inspect_binder", "FStar.Pervasives.Native.tuple2", "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.fresh" ]
[]
false
true
false
false
false
let open_term_simple (b: R.simple_binder) (t: term) : Tac (simple_binder & term) =
let n = fresh () in let bv:binder_view = inspect_binder b in let nv:R.namedv = pack_namedv ({ uniq = n; sort = seal bv.sort; ppname = bv.ppname }) in let t' = subst_term [DB 0 nv] t in let bndr:binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs } in (bndr, t')
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.generate_st
val generate_st : a: Hacl.HMAC_DRBG.supported_alg -> Type0
let generate_st (a:supported_alg) = output:buffer uint8 -> st:state a -> n:size_t -> additional_input_len:size_t -> additional_input:lbuffer uint8 additional_input_len -> Stack bool (requires fun h0 -> live h0 output /\ invariant st h0 /\ live h0 additional_input /\ disjoint_st st output /\ disjoint_st st additional_input /\ disjoint output additional_input /\ v n = length output /\ v n <= S.max_output_length /\ v additional_input_len <= S.max_additional_input_length) (ensures fun h0 b h1 -> S.hmac_input_bound a; match S.generate (repr st h0) (v n) (as_seq h0 additional_input) with | None -> b = false /\ invariant st h1 /\ modifies0 h0 h1 | Some (out, st_) -> b = true /\ invariant st h1 /\ B.modifies (loc output |+| footprint st) h0 h1 /\ repr st h1 == st_ /\ as_seq #MUT #_ #n h1 output == out)
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 231, "start_col": 0, "start_line": 208 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) [@@ Comment "Return the minimal entropy input length of the desired hash function. @param a Hash algorithm to use."] let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) val state: supported_alg -> Type0 inline_for_extraction noextract val freeable: #a:supported_alg -> st:state a -> Type0 val footprint: #a:supported_alg -> st:state a -> GTot B.loc inline_for_extraction noextract val invariant: #a:supported_alg -> st:state a -> h:HS.mem -> Type0 inline_for_extraction noextract let disjoint_st (#a:supported_alg) (st:state a) (b:buffer uint8) = B.loc_disjoint (footprint st) (B.loc_buffer b) val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) inline_for_extraction noextract val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st)) /\ invariant st h1) [@@ Comment "Create a DRBG state. @param a Hash algorithm to use. The possible instantiations are ... * `Spec_Hash_Definitions_SHA2_256`, * `Spec_Hash_Definitions_SHA2_384`, * `Spec_Hash_Definitions_SHA2_512`, and * `Spec_Hash_Definitions_SHA1`."] inline_for_extraction val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st) h0 h1 /\ B.(loc_includes (loc_region_only true r)) (footprint st) /\ invariant st h1 /\ freeable st) inline_for_extraction noextract let instantiate_st (a:supported_alg) = st:state a -> entropy_input_len:size_t -> entropy_input:lbuffer uint8 entropy_input_len -> nonce_len:size_t -> nonce:lbuffer uint8 nonce_len -> personalization_string_len:size_t -> personalization_string:lbuffer uint8 personalization_string_len -> Stack unit (requires fun h0 -> live h0 entropy_input /\ live h0 nonce /\ live h0 personalization_string /\ invariant st h0 /\ S.min_length a <= v entropy_input_len /\ v entropy_input_len <= v max_length /\ S.min_length a / 2 <= v nonce_len /\ v nonce_len <= v max_length /\ v personalization_string_len <= S.max_personalization_string_length) (ensures fun h0 _ h1 -> S.hmac_input_bound a; invariant st h1 /\ B.modifies (footprint st) h0 h1 /\ repr st h1 == S.instantiate (as_seq h0 entropy_input) (as_seq h0 nonce) (as_seq h0 personalization_string)) inline_for_extraction noextract val mk_instantiate: #a:supported_alg -> hmac:HMAC.compute_st a -> instantiate_st a [@@ Comment "Instantiate the DRBG. @param a Hash algorithm to use. (Value must match the value used in `Hacl_HMAC_DRBG_create_in`.) @param st Pointer to DRBG state. @param entropy_input_len Length of entropy input. @param entropy_input Pointer to `entropy_input_len` bytes of memory where entropy input is read from. @param nonce_len Length of nonce. @param nonce Pointer to `nonce_len` bytes of memory where nonce is read from. @param personalization_string_len length of personalization string. @param personalization_string Pointer to `personalization_string_len` bytes of memory where personalization string is read from."] val instantiate: a:supported_alg -> instantiate_st a inline_for_extraction noextract let reseed_st (a:supported_alg) = st:state a -> entropy_input_len:size_t -> entropy_input:lbuffer uint8 entropy_input_len -> additional_input_len:size_t -> additional_input:lbuffer uint8 additional_input_len -> Stack unit (requires fun h0 -> invariant st h0 /\ live h0 entropy_input /\ live h0 additional_input /\ disjoint_st st entropy_input /\ disjoint_st st additional_input /\ S.min_length a <= v entropy_input_len /\ v entropy_input_len <= v max_length /\ v additional_input_len <= S.max_additional_input_length) (ensures fun h0 _ h1 -> S.hmac_input_bound a; invariant st h1 /\ B.modifies (footprint st) h0 h1 /\ repr st h1 == S.reseed (repr st h0) (as_seq h0 entropy_input) (as_seq h0 additional_input)) inline_for_extraction noextract val mk_reseed: #a:supported_alg -> hmac:HMAC.compute_st a -> reseed_st a [@@ Comment "Reseed the DRBG. @param a Hash algorithm to use. (Value must match the value used in `Hacl_HMAC_DRBG_create_in`.) @param st Pointer to DRBG state. @param entropy_input_len Length of entropy input. @param entropy_input Pointer to `entropy_input_len` bytes of memory where entropy input is read from. @param additional_input_input_len Length of additional input. @param additional_input_input Pointer to `additional_input_input_len` bytes of memory where additional input is read from."] val reseed: a:supported_alg -> reseed_st a
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.HMAC_DRBG.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.HMAC_DRBG.supported_alg", "Lib.Buffer.buffer", "Lib.IntTypes.uint8", "Hacl.HMAC_DRBG.state", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Prims.bool", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.HMAC_DRBG.invariant", "Hacl.HMAC_DRBG.disjoint_st", "Lib.Buffer.disjoint", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Lib.IntTypes.U32", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Lib.Buffer.length", "Prims.op_LessThanOrEqual", "Spec.HMAC_DRBG.max_output_length", "Spec.HMAC_DRBG.max_additional_input_length", "Spec.HMAC_DRBG.generate", "Hacl.HMAC_DRBG.repr", "Lib.Buffer.as_seq", "Lib.Buffer.modifies0", "Spec.Agile.HMAC.lbytes", "Spec.HMAC_DRBG.state", "LowStar.Monotonic.Buffer.modifies", "Lib.Buffer.op_Bar_Plus_Bar", "Lib.Buffer.loc", "Hacl.HMAC_DRBG.footprint", "Prims.eq2", "FStar.Seq.Base.seq", "Prims.nat", "FStar.Seq.Base.length", "Prims.unit", "Spec.HMAC_DRBG.hmac_input_bound" ]
[]
false
false
false
true
true
let generate_st (a: supported_alg) =
output: buffer uint8 -> st: state a -> n: size_t -> additional_input_len: size_t -> additional_input: lbuffer uint8 additional_input_len -> Stack bool (requires fun h0 -> live h0 output /\ invariant st h0 /\ live h0 additional_input /\ disjoint_st st output /\ disjoint_st st additional_input /\ disjoint output additional_input /\ v n = length output /\ v n <= S.max_output_length /\ v additional_input_len <= S.max_additional_input_length) (ensures fun h0 b h1 -> S.hmac_input_bound a; match S.generate (repr st h0) (v n) (as_seq h0 additional_input) with | None -> b = false /\ invariant st h1 /\ modifies0 h0 h1 | Some (out, st_) -> b = true /\ invariant st h1 /\ B.modifies (loc output |+| footprint st) h0 h1 /\ repr st h1 == st_ /\ as_seq #MUT #_ #n h1 output == out)
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.__open_term_n_aux
val __open_term_n_aux (bs: list R.binder) (nbs: list binder) (s: subst_t) : Tac (list binder & subst_t)
val __open_term_n_aux (bs: list R.binder) (nbs: list binder) (s: subst_t) : Tac (list binder & subst_t)
let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s)
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 62, "end_line": 243, "start_col": 0, "start_line": 236 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
bs: Prims.list FStar.Stubs.Reflection.Types.binder -> nbs: Prims.list FStar.Tactics.NamedView.binder -> s: FStar.Stubs.Syntax.Syntax.subst_t -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binder * FStar.Stubs.Syntax.Syntax.subst_t)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Stubs.Reflection.Types.binder", "FStar.Tactics.NamedView.binder", "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.NamedView.__open_term_n_aux", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Stubs.Syntax.Syntax.DB", "FStar.Reflection.V2.Derived.shift_subst", "FStar.Stubs.Reflection.Types.namedv", "FStar.Tactics.NamedView.r_binder_to_namedv", "FStar.Tactics.NamedView.open_binder", "FStar.Tactics.NamedView.r_subst_binder_sort" ]
[ "recursion" ]
false
true
false
false
false
let rec __open_term_n_aux (bs: list R.binder) (nbs: list binder) (s: subst_t) : Tac (list binder & subst_t) =
match bs with | [] -> nbs, s | b :: bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b :: nbs) (DB 0 nv :: shift_subst 1 s)
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_branch
val close_branch (b: branch) : Tot R.branch
val close_branch (b: branch) : Tot R.branch
let close_branch (b : branch) : Tot R.branch = let (pat, t) = b in let pat, s = close_pat pat [] in let t' = subst_term s t in (pat, t')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 371, "start_col": 0, "start_line": 367 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t private let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'') private let rec close_term_n_simple (bs : list simple_binder) (t : term) : list R.simple_binder & term = match bs with | [] -> ([], t) | b::bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b'::bs', t'') private let rec open_pat (p : R.pattern) (s : subst_t) : Tac (pattern & subst_t) = match p with | R.Pat_Constant c -> Pat_Constant {c=c}, s | R.Pat_Var ssort n -> let sort = unseal ssort in let sort = subst_term s sort in let nvv : namedv = { uniq = fresh(); sort = seal sort; ppname = n; } in let nv = pack_namedv nvv in Pat_Var {v=nvv; sort=seal sort}, (DB 0 nv) :: shift_subst 1 s | R.Pat_Cons head univs subpats -> let subpats, s = fold_left (fun (pats,s) (pat,b) -> let pat, s' = open_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in Pat_Cons {head=head; univs=univs; subpats=subpats}, s | R.Pat_Dot_Term None -> Pat_Dot_Term {t=None}, s | R.Pat_Dot_Term (Some t) -> let t = subst_term s t in Pat_Dot_Term {t=Some t}, s private let open_branch (b : R.branch) : Tac branch = let (pat, t) = b in let pat, s = open_pat pat [] in let t' = subst_term s t in (pat, t') private let rec close_pat (p : pattern) (s : subst_t) : Tot (R.pattern & subst_t) = match p with | Pat_Constant {c} -> R.Pat_Constant c, s | Pat_Var {v; sort} -> let nv = pack_namedv v in (* NOTE: we cannot do anything on the sort wihtout going into TAC. Need a sealed_bind. *) //let sort = unseal sort in //let sort = subst_term s sort in //let sort = seal sort in let s = (NM nv 0) :: shift_subst 1 s in R.Pat_Var sort v.ppname, s | Pat_Cons {head; univs; subpats} -> let subpats, s = List.Tot.fold_left (fun (pats,s) (pat,b) -> assume(pat << p); let pat, s' = close_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in R.Pat_Cons head univs subpats, s | Pat_Dot_Term {t=None} -> R.Pat_Dot_Term None, s | Pat_Dot_Term {t=Some t} -> let t = subst_term s t in R.Pat_Dot_Term (Some t), s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Tactics.NamedView.branch -> FStar.Stubs.Reflection.V2.Data.branch
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.branch", "FStar.Tactics.NamedView.pattern", "FStar.Tactics.NamedView.term", "FStar.Stubs.Reflection.V2.Data.pattern", "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "FStar.Stubs.Reflection.V2.Data.branch", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.NamedView.close_pat", "Prims.Nil", "FStar.Stubs.Syntax.Syntax.subst_elt" ]
[]
false
false
false
true
false
let close_branch (b: branch) : Tot R.branch =
let pat, t = b in let pat, s = close_pat pat [] in let t' = subst_term s t in (pat, t')
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_comp_simple
val open_comp_simple (b: R.simple_binder) (t: comp) : Tac (simple_binder & comp)
val open_comp_simple (b: R.simple_binder) (t: comp) : Tac (simple_binder & comp)
let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 193, "start_col": 0, "start_line": 175 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Stubs.Reflection.V2.Data.simple_binder -> t: FStar.Tactics.NamedView.comp -> FStar.Tactics.Effect.Tac (FStar.Tactics.NamedView.simple_binder * FStar.Tactics.NamedView.comp)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.V2.Data.simple_binder", "FStar.Tactics.NamedView.comp", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.NamedView.simple_binder", "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.Mkbinder", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__ppname", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__sort", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__qual", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs", "FStar.Tactics.NamedView.subst_comp", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Stubs.Syntax.Syntax.DB", "Prims.Nil", "FStar.Stubs.Reflection.Types.namedv", "FStar.Stubs.Reflection.V2.Builtins.pack_namedv", "FStar.Stubs.Reflection.V2.Data.Mknamedv_view", "FStar.Sealed.seal", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Reflection.V2.Data.binder_view", "FStar.Stubs.Reflection.V2.Builtins.inspect_binder", "FStar.Pervasives.Native.tuple2", "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.fresh" ]
[]
false
true
false
false
false
let open_comp_simple (b: R.simple_binder) (t: comp) : Tac (simple_binder & comp) =
let n = fresh () in let bv:binder_view = inspect_binder b in let nv:R.namedv = pack_namedv ({ uniq = n; sort = seal bv.sort; ppname = bv.ppname }) in let t' = subst_comp [DB 0 nv] t in let bndr:binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs } in (bndr, t')
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.inspect
val inspect (t:term) : Tac named_term_view
val inspect (t:term) : Tac named_term_view
let inspect (t:term) : Tac named_term_view = let t = compress t in let tv = inspect_ln t in open_view tv
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 14, "end_line": 513, "start_col": 0, "start_line": 510 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t private let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'') private let rec close_term_n_simple (bs : list simple_binder) (t : term) : list R.simple_binder & term = match bs with | [] -> ([], t) | b::bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b'::bs', t'') private let rec open_pat (p : R.pattern) (s : subst_t) : Tac (pattern & subst_t) = match p with | R.Pat_Constant c -> Pat_Constant {c=c}, s | R.Pat_Var ssort n -> let sort = unseal ssort in let sort = subst_term s sort in let nvv : namedv = { uniq = fresh(); sort = seal sort; ppname = n; } in let nv = pack_namedv nvv in Pat_Var {v=nvv; sort=seal sort}, (DB 0 nv) :: shift_subst 1 s | R.Pat_Cons head univs subpats -> let subpats, s = fold_left (fun (pats,s) (pat,b) -> let pat, s' = open_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in Pat_Cons {head=head; univs=univs; subpats=subpats}, s | R.Pat_Dot_Term None -> Pat_Dot_Term {t=None}, s | R.Pat_Dot_Term (Some t) -> let t = subst_term s t in Pat_Dot_Term {t=Some t}, s private let open_branch (b : R.branch) : Tac branch = let (pat, t) = b in let pat, s = open_pat pat [] in let t' = subst_term s t in (pat, t') private let rec close_pat (p : pattern) (s : subst_t) : Tot (R.pattern & subst_t) = match p with | Pat_Constant {c} -> R.Pat_Constant c, s | Pat_Var {v; sort} -> let nv = pack_namedv v in (* NOTE: we cannot do anything on the sort wihtout going into TAC. Need a sealed_bind. *) //let sort = unseal sort in //let sort = subst_term s sort in //let sort = seal sort in let s = (NM nv 0) :: shift_subst 1 s in R.Pat_Var sort v.ppname, s | Pat_Cons {head; univs; subpats} -> let subpats, s = List.Tot.fold_left (fun (pats,s) (pat,b) -> assume(pat << p); let pat, s' = close_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in R.Pat_Cons head univs subpats, s | Pat_Dot_Term {t=None} -> R.Pat_Dot_Term None, s | Pat_Dot_Term {t=Some t} -> let t = subst_term s t in R.Pat_Dot_Term (Some t), s private let close_branch (b : branch) : Tot R.branch = let (pat, t) = b in let pat, s = close_pat pat [] in let t' = subst_term s t in (pat, t') private let open_match_returns_ascription (mra : R.match_returns_ascription) : Tac match_returns_ascription = let (b, (ct, topt, use_eq)) = mra in let nb = open_binder b in let ct = match ct with | Inl t -> Inl (open_term_with b nb t) | Inr c -> let c = inspect_comp c in let c = open_comp_with b nb c in Inr c in let topt = match topt with | None -> None | Some t -> Some (open_term_with b nb t) in (nb, (ct, topt, use_eq)) private let close_match_returns_ascription (mra : match_returns_ascription) : R.match_returns_ascription = let (nb, (ct, topt, use_eq)) = mra in let b = close_binder nb in // FIXME: all this is repeating the close_binder work, for no good reason let ct = match ct with | Inl t -> Inl (snd (close_term nb t)) | Inr c -> let _, c = close_comp nb c in let c = pack_comp c in Inr c in let topt = match topt with | None -> None | Some t -> Some (snd (close_term nb t)) in (b, (ct, topt, use_eq)) private let open_view (tv:term_view) : Tac named_term_view = match tv with (* Nothing interesting *) | RD.Tv_Var v -> Tv_Var (inspect_namedv v) | RD.Tv_BVar v -> Tv_BVar (inspect_bv v) | RD.Tv_FVar v -> Tv_FVar v | RD.Tv_UInst v us -> Tv_UInst v us | RD.Tv_App hd a -> Tv_App hd a | RD.Tv_Type u -> Tv_Type u | RD.Tv_Const c -> Tv_Const c | RD.Tv_Uvar n ctx_uvar_and_subst -> Tv_Uvar n ctx_uvar_and_subst | RD.Tv_AscribedT e t tac use_eq -> Tv_AscribedT e t tac use_eq | RD.Tv_AscribedC e c tac use_eq -> Tv_AscribedC e (inspect_comp c) tac use_eq | RD.Tv_Unknown -> Tv_Unknown | RD.Tv_Unsupp -> Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | RD.Tv_Abs b body -> let nb, body = open_term b body in Tv_Abs nb body | RD.Tv_Arrow b c -> let nb, c = open_comp b (inspect_comp c) in Tv_Arrow nb c | RD.Tv_Refine b ref -> let nb, ref = open_term_simple b ref in Tv_Refine nb ref | RD.Tv_Let recf attrs b def body -> let nb, body = open_term_simple b body in let def = if recf then subst_term [DB 0 (r_binder_to_namedv nb)] def else def in Tv_Let recf attrs nb def body | RD.Tv_Match scrutinee ret brs -> let brs = map open_branch brs in let ret = map_opt open_match_returns_ascription ret in Tv_Match scrutinee ret brs private let close_view (tv : named_term_view) : Tot term_view = match tv with (* Nothing interesting *) | Tv_Var v -> RD.Tv_Var (pack_namedv v) | Tv_BVar v -> RD.Tv_BVar (pack_bv v) | Tv_FVar v -> RD.Tv_FVar v | Tv_UInst v us -> RD.Tv_UInst v us | Tv_App hd a -> RD.Tv_App hd a | Tv_Type u -> RD.Tv_Type u | Tv_Const c -> RD.Tv_Const c | Tv_Uvar n ctx_uvar_and_subst -> RD.Tv_Uvar n ctx_uvar_and_subst | Tv_AscribedT e t tac use_eq -> RD.Tv_AscribedT e t tac use_eq | Tv_AscribedC e c tac use_eq -> RD.Tv_AscribedC e (pack_comp c) tac use_eq | Tv_Unknown -> RD.Tv_Unknown | Tv_Unsupp -> RD.Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | Tv_Abs nb body -> let b, body = close_term nb body in RD.Tv_Abs b body | Tv_Arrow nb c -> let b, c = close_comp nb c in let c = pack_comp c in RD.Tv_Arrow b c | Tv_Refine nb ref -> let b, ref = close_term_simple nb ref in RD.Tv_Refine b ref | Tv_Let recf attrs nb def body -> let def = if recf then subst_term [NM (r_binder_to_namedv nb) 0] def else def in let b, body = close_term_simple nb body in RD.Tv_Let recf attrs b def body | Tv_Match scrutinee ret brs -> let brs = List.Tot.map close_branch brs in (* NOTE: this used to use FStar.Option.mapTot, but that brings in way too many dependencies. *) let ret = match ret with | None -> None | Some asc -> Some (close_match_returns_ascription asc) in RD.Tv_Match scrutinee ret brs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.named_term_view
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.open_view", "FStar.Tactics.NamedView.named_term_view", "FStar.Stubs.Reflection.V2.Data.term_view", "Prims.precedes", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.inspect_ln", "FStar.Stubs.Tactics.V2.Builtins.compress" ]
[]
false
true
false
false
false
let inspect (t: term) : Tac named_term_view =
let t = compress t in let tv = inspect_ln t in open_view tv
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_term_n
val close_term_n (bs: list binder) (t: term) : list R.binder & term
val close_term_n (bs: list binder) (t: term) : list R.binder & term
let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 272, "start_col": 0, "start_line": 261 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
bs: Prims.list FStar.Tactics.NamedView.binder -> t: FStar.Tactics.NamedView.term -> Prims.list FStar.Stubs.Reflection.Types.binder * FStar.Tactics.NamedView.term
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.term", "FStar.Stubs.Reflection.Types.binder", "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Pervasives.Native.Mktuple2", "FStar.List.Tot.Base.rev", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "FStar.Pervasives.Native.tuple2", "Prims.Nil", "FStar.Stubs.Syntax.Syntax.subst_elt", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.NM", "FStar.Reflection.V2.Derived.shift_subst", "FStar.Tactics.NamedView.close_binder", "FStar.Stubs.Reflection.Types.namedv", "FStar.Tactics.NamedView.r_binder_to_namedv", "FStar.Tactics.NamedView.subst_binder_sort" ]
[]
false
false
false
true
false
let close_term_n (bs: list binder) (t: term) : list R.binder & term =
let rec aux (bs: list binder) (cbs: list R.binder) (s: subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b :: bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b :: cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_univ_s
val open_univ_s (us: list R.univ_name) : Tac (list univ_name & subst_t)
val open_univ_s (us: list R.univ_name) : Tac (list univ_name & subst_t)
let open_univ_s (us : list R.univ_name) : Tac (list univ_name & subst_t) = let n = List.Tot.length us in let s = mapi (fun i u -> UN (n-1-i) (R.pack_universe (R.Uv_Name u))) us in Util.map (fun i -> inspect_ident i) us, s
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 43, "end_line": 524, "start_col": 0, "start_line": 521 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t private let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'') private let rec close_term_n_simple (bs : list simple_binder) (t : term) : list R.simple_binder & term = match bs with | [] -> ([], t) | b::bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b'::bs', t'') private let rec open_pat (p : R.pattern) (s : subst_t) : Tac (pattern & subst_t) = match p with | R.Pat_Constant c -> Pat_Constant {c=c}, s | R.Pat_Var ssort n -> let sort = unseal ssort in let sort = subst_term s sort in let nvv : namedv = { uniq = fresh(); sort = seal sort; ppname = n; } in let nv = pack_namedv nvv in Pat_Var {v=nvv; sort=seal sort}, (DB 0 nv) :: shift_subst 1 s | R.Pat_Cons head univs subpats -> let subpats, s = fold_left (fun (pats,s) (pat,b) -> let pat, s' = open_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in Pat_Cons {head=head; univs=univs; subpats=subpats}, s | R.Pat_Dot_Term None -> Pat_Dot_Term {t=None}, s | R.Pat_Dot_Term (Some t) -> let t = subst_term s t in Pat_Dot_Term {t=Some t}, s private let open_branch (b : R.branch) : Tac branch = let (pat, t) = b in let pat, s = open_pat pat [] in let t' = subst_term s t in (pat, t') private let rec close_pat (p : pattern) (s : subst_t) : Tot (R.pattern & subst_t) = match p with | Pat_Constant {c} -> R.Pat_Constant c, s | Pat_Var {v; sort} -> let nv = pack_namedv v in (* NOTE: we cannot do anything on the sort wihtout going into TAC. Need a sealed_bind. *) //let sort = unseal sort in //let sort = subst_term s sort in //let sort = seal sort in let s = (NM nv 0) :: shift_subst 1 s in R.Pat_Var sort v.ppname, s | Pat_Cons {head; univs; subpats} -> let subpats, s = List.Tot.fold_left (fun (pats,s) (pat,b) -> assume(pat << p); let pat, s' = close_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in R.Pat_Cons head univs subpats, s | Pat_Dot_Term {t=None} -> R.Pat_Dot_Term None, s | Pat_Dot_Term {t=Some t} -> let t = subst_term s t in R.Pat_Dot_Term (Some t), s private let close_branch (b : branch) : Tot R.branch = let (pat, t) = b in let pat, s = close_pat pat [] in let t' = subst_term s t in (pat, t') private let open_match_returns_ascription (mra : R.match_returns_ascription) : Tac match_returns_ascription = let (b, (ct, topt, use_eq)) = mra in let nb = open_binder b in let ct = match ct with | Inl t -> Inl (open_term_with b nb t) | Inr c -> let c = inspect_comp c in let c = open_comp_with b nb c in Inr c in let topt = match topt with | None -> None | Some t -> Some (open_term_with b nb t) in (nb, (ct, topt, use_eq)) private let close_match_returns_ascription (mra : match_returns_ascription) : R.match_returns_ascription = let (nb, (ct, topt, use_eq)) = mra in let b = close_binder nb in // FIXME: all this is repeating the close_binder work, for no good reason let ct = match ct with | Inl t -> Inl (snd (close_term nb t)) | Inr c -> let _, c = close_comp nb c in let c = pack_comp c in Inr c in let topt = match topt with | None -> None | Some t -> Some (snd (close_term nb t)) in (b, (ct, topt, use_eq)) private let open_view (tv:term_view) : Tac named_term_view = match tv with (* Nothing interesting *) | RD.Tv_Var v -> Tv_Var (inspect_namedv v) | RD.Tv_BVar v -> Tv_BVar (inspect_bv v) | RD.Tv_FVar v -> Tv_FVar v | RD.Tv_UInst v us -> Tv_UInst v us | RD.Tv_App hd a -> Tv_App hd a | RD.Tv_Type u -> Tv_Type u | RD.Tv_Const c -> Tv_Const c | RD.Tv_Uvar n ctx_uvar_and_subst -> Tv_Uvar n ctx_uvar_and_subst | RD.Tv_AscribedT e t tac use_eq -> Tv_AscribedT e t tac use_eq | RD.Tv_AscribedC e c tac use_eq -> Tv_AscribedC e (inspect_comp c) tac use_eq | RD.Tv_Unknown -> Tv_Unknown | RD.Tv_Unsupp -> Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | RD.Tv_Abs b body -> let nb, body = open_term b body in Tv_Abs nb body | RD.Tv_Arrow b c -> let nb, c = open_comp b (inspect_comp c) in Tv_Arrow nb c | RD.Tv_Refine b ref -> let nb, ref = open_term_simple b ref in Tv_Refine nb ref | RD.Tv_Let recf attrs b def body -> let nb, body = open_term_simple b body in let def = if recf then subst_term [DB 0 (r_binder_to_namedv nb)] def else def in Tv_Let recf attrs nb def body | RD.Tv_Match scrutinee ret brs -> let brs = map open_branch brs in let ret = map_opt open_match_returns_ascription ret in Tv_Match scrutinee ret brs private let close_view (tv : named_term_view) : Tot term_view = match tv with (* Nothing interesting *) | Tv_Var v -> RD.Tv_Var (pack_namedv v) | Tv_BVar v -> RD.Tv_BVar (pack_bv v) | Tv_FVar v -> RD.Tv_FVar v | Tv_UInst v us -> RD.Tv_UInst v us | Tv_App hd a -> RD.Tv_App hd a | Tv_Type u -> RD.Tv_Type u | Tv_Const c -> RD.Tv_Const c | Tv_Uvar n ctx_uvar_and_subst -> RD.Tv_Uvar n ctx_uvar_and_subst | Tv_AscribedT e t tac use_eq -> RD.Tv_AscribedT e t tac use_eq | Tv_AscribedC e c tac use_eq -> RD.Tv_AscribedC e (pack_comp c) tac use_eq | Tv_Unknown -> RD.Tv_Unknown | Tv_Unsupp -> RD.Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | Tv_Abs nb body -> let b, body = close_term nb body in RD.Tv_Abs b body | Tv_Arrow nb c -> let b, c = close_comp nb c in let c = pack_comp c in RD.Tv_Arrow b c | Tv_Refine nb ref -> let b, ref = close_term_simple nb ref in RD.Tv_Refine b ref | Tv_Let recf attrs nb def body -> let def = if recf then subst_term [NM (r_binder_to_namedv nb) 0] def else def in let b, body = close_term_simple nb body in RD.Tv_Let recf attrs b def body | Tv_Match scrutinee ret brs -> let brs = List.Tot.map close_branch brs in (* NOTE: this used to use FStar.Option.mapTot, but that brings in way too many dependencies. *) let ret = match ret with | None -> None | Some asc -> Some (close_match_returns_ascription asc) in RD.Tv_Match scrutinee ret brs [@@plugin; coercion] let inspect (t:term) : Tac named_term_view = let t = compress t in let tv = inspect_ln t in open_view tv [@@plugin; coercion] let pack (tv:named_term_view) : Tot term = let tv = close_view tv in pack_ln tv
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
us: Prims.list FStar.Stubs.Reflection.Types.univ_name -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.univ_name * FStar.Stubs.Syntax.Syntax.subst_t)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Stubs.Reflection.Types.univ_name", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.NamedView.univ_name", "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.Util.map", "FStar.Stubs.Reflection.Types.ident", "FStar.Stubs.Reflection.V2.Data.ident_view", "FStar.Stubs.Reflection.V2.Builtins.inspect_ident", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Tactics.Util.mapi", "Prims.nat", "FStar.Stubs.Syntax.Syntax.UN", "Prims.op_Subtraction", "FStar.Stubs.Reflection.V2.Builtins.pack_universe", "FStar.Stubs.Reflection.V2.Data.Uv_Name", "FStar.List.Tot.Base.length" ]
[]
false
true
false
false
false
let open_univ_s (us: list R.univ_name) : Tac (list univ_name & subst_t) =
let n = List.Tot.length us in let s = mapi (fun i u -> UN (n - 1 - i) (R.pack_universe (R.Uv_Name u))) us in Util.map (fun i -> inspect_ident i) us, s
false
Hacl.HMAC_DRBG.fsti
Hacl.HMAC_DRBG.reseed_st
val reseed_st : a: Hacl.HMAC_DRBG.supported_alg -> Type0
let reseed_st (a:supported_alg) = st:state a -> entropy_input_len:size_t -> entropy_input:lbuffer uint8 entropy_input_len -> additional_input_len:size_t -> additional_input:lbuffer uint8 additional_input_len -> Stack unit (requires fun h0 -> invariant st h0 /\ live h0 entropy_input /\ live h0 additional_input /\ disjoint_st st entropy_input /\ disjoint_st st additional_input /\ S.min_length a <= v entropy_input_len /\ v entropy_input_len <= v max_length /\ v additional_input_len <= S.max_additional_input_length) (ensures fun h0 _ h1 -> S.hmac_input_bound a; invariant st h1 /\ B.modifies (footprint st) h0 h1 /\ repr st h1 == S.reseed (repr st h0) (as_seq h0 entropy_input) (as_seq h0 additional_input))
{ "file_name": "code/drbg/Hacl.HMAC_DRBG.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 192, "start_col": 0, "start_line": 172 }
module Hacl.HMAC_DRBG open FStar.HyperStack.ST open Spec.Hash.Definitions open Lib.IntTypes open Lib.Buffer module HS = FStar.HyperStack module B = LowStar.Buffer module LSeq = Lib.Sequence module HMAC = Hacl.HMAC module S = Spec.HMAC_DRBG /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements the hash-algorithm-agile algorithms /// - HMAC_DRBG_Update (not exposed by the interface) /// - HMAC_DRBG_Instantiate_algorithm /// - HMAC_DRBG_Reseed_algorithm /// - HMAC_DRBG_Generate_algorithm /// /// This is not linked to an appropriate Get_entropy_input function, /// so these algorithms should be combined to get entropy from Get_entropy_input /// for instantiation, reseeding, and optional prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 hash algorithms /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// /// - The reseed_interval is 2^10 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let supported_alg = S.supported_alg let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) [@@ Comment "Return the minimal entropy input length of the desired hash function. @param a Hash algorithm to use."] let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) val state: supported_alg -> Type0 inline_for_extraction noextract val freeable: #a:supported_alg -> st:state a -> Type0 val footprint: #a:supported_alg -> st:state a -> GTot B.loc inline_for_extraction noextract val invariant: #a:supported_alg -> st:state a -> h:HS.mem -> Type0 inline_for_extraction noextract let disjoint_st (#a:supported_alg) (st:state a) (b:buffer uint8) = B.loc_disjoint (footprint st) (B.loc_buffer b) val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) inline_for_extraction noextract val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st)) /\ invariant st h1) [@@ Comment "Create a DRBG state. @param a Hash algorithm to use. The possible instantiations are ... * `Spec_Hash_Definitions_SHA2_256`, * `Spec_Hash_Definitions_SHA2_384`, * `Spec_Hash_Definitions_SHA2_512`, and * `Spec_Hash_Definitions_SHA1`."] inline_for_extraction val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st) h0 h1 /\ B.(loc_includes (loc_region_only true r)) (footprint st) /\ invariant st h1 /\ freeable st) inline_for_extraction noextract let instantiate_st (a:supported_alg) = st:state a -> entropy_input_len:size_t -> entropy_input:lbuffer uint8 entropy_input_len -> nonce_len:size_t -> nonce:lbuffer uint8 nonce_len -> personalization_string_len:size_t -> personalization_string:lbuffer uint8 personalization_string_len -> Stack unit (requires fun h0 -> live h0 entropy_input /\ live h0 nonce /\ live h0 personalization_string /\ invariant st h0 /\ S.min_length a <= v entropy_input_len /\ v entropy_input_len <= v max_length /\ S.min_length a / 2 <= v nonce_len /\ v nonce_len <= v max_length /\ v personalization_string_len <= S.max_personalization_string_length) (ensures fun h0 _ h1 -> S.hmac_input_bound a; invariant st h1 /\ B.modifies (footprint st) h0 h1 /\ repr st h1 == S.instantiate (as_seq h0 entropy_input) (as_seq h0 nonce) (as_seq h0 personalization_string)) inline_for_extraction noextract val mk_instantiate: #a:supported_alg -> hmac:HMAC.compute_st a -> instantiate_st a [@@ Comment "Instantiate the DRBG. @param a Hash algorithm to use. (Value must match the value used in `Hacl_HMAC_DRBG_create_in`.) @param st Pointer to DRBG state. @param entropy_input_len Length of entropy input. @param entropy_input Pointer to `entropy_input_len` bytes of memory where entropy input is read from. @param nonce_len Length of nonce. @param nonce Pointer to `nonce_len` bytes of memory where nonce is read from. @param personalization_string_len length of personalization string. @param personalization_string Pointer to `personalization_string_len` bytes of memory where personalization string is read from."] val instantiate: a:supported_alg -> instantiate_st a
{ "checked_file": "/", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.HMAC.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HMAC_DRBG.fsti" }
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.HMAC", "short_module": "HMAC" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.HMAC_DRBG.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.HMAC_DRBG.supported_alg", "Hacl.HMAC_DRBG.state", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Hacl.HMAC_DRBG.invariant", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.HMAC_DRBG.disjoint_st", "Prims.b2t", "Prims.op_LessThanOrEqual", "Spec.HMAC_DRBG.min_length", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.HMAC_DRBG.max_length", "Spec.HMAC_DRBG.max_additional_input_length", "LowStar.Monotonic.Buffer.modifies", "Hacl.HMAC_DRBG.footprint", "Prims.eq2", "Spec.HMAC_DRBG.state", "Hacl.HMAC_DRBG.repr", "Spec.HMAC_DRBG.reseed", "Lib.Buffer.as_seq", "Spec.HMAC_DRBG.hmac_input_bound" ]
[]
false
false
false
true
true
let reseed_st (a: supported_alg) =
st: state a -> entropy_input_len: size_t -> entropy_input: lbuffer uint8 entropy_input_len -> additional_input_len: size_t -> additional_input: lbuffer uint8 additional_input_len -> Stack unit (requires fun h0 -> invariant st h0 /\ live h0 entropy_input /\ live h0 additional_input /\ disjoint_st st entropy_input /\ disjoint_st st additional_input /\ S.min_length a <= v entropy_input_len /\ v entropy_input_len <= v max_length /\ v additional_input_len <= S.max_additional_input_length) (ensures fun h0 _ h1 -> S.hmac_input_bound a; invariant st h1 /\ B.modifies (footprint st) h0 h1 /\ repr st h1 == S.reseed (repr st h0) (as_seq h0 entropy_input) (as_seq h0 additional_input) )
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.pack
val pack (tv:named_term_view) : Tot term
val pack (tv:named_term_view) : Tot term
let pack (tv:named_term_view) : Tot term = let tv = close_view tv in pack_ln tv
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 518, "start_col": 0, "start_line": 516 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t private let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'') private let rec close_term_n_simple (bs : list simple_binder) (t : term) : list R.simple_binder & term = match bs with | [] -> ([], t) | b::bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b'::bs', t'') private let rec open_pat (p : R.pattern) (s : subst_t) : Tac (pattern & subst_t) = match p with | R.Pat_Constant c -> Pat_Constant {c=c}, s | R.Pat_Var ssort n -> let sort = unseal ssort in let sort = subst_term s sort in let nvv : namedv = { uniq = fresh(); sort = seal sort; ppname = n; } in let nv = pack_namedv nvv in Pat_Var {v=nvv; sort=seal sort}, (DB 0 nv) :: shift_subst 1 s | R.Pat_Cons head univs subpats -> let subpats, s = fold_left (fun (pats,s) (pat,b) -> let pat, s' = open_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in Pat_Cons {head=head; univs=univs; subpats=subpats}, s | R.Pat_Dot_Term None -> Pat_Dot_Term {t=None}, s | R.Pat_Dot_Term (Some t) -> let t = subst_term s t in Pat_Dot_Term {t=Some t}, s private let open_branch (b : R.branch) : Tac branch = let (pat, t) = b in let pat, s = open_pat pat [] in let t' = subst_term s t in (pat, t') private let rec close_pat (p : pattern) (s : subst_t) : Tot (R.pattern & subst_t) = match p with | Pat_Constant {c} -> R.Pat_Constant c, s | Pat_Var {v; sort} -> let nv = pack_namedv v in (* NOTE: we cannot do anything on the sort wihtout going into TAC. Need a sealed_bind. *) //let sort = unseal sort in //let sort = subst_term s sort in //let sort = seal sort in let s = (NM nv 0) :: shift_subst 1 s in R.Pat_Var sort v.ppname, s | Pat_Cons {head; univs; subpats} -> let subpats, s = List.Tot.fold_left (fun (pats,s) (pat,b) -> assume(pat << p); let pat, s' = close_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in R.Pat_Cons head univs subpats, s | Pat_Dot_Term {t=None} -> R.Pat_Dot_Term None, s | Pat_Dot_Term {t=Some t} -> let t = subst_term s t in R.Pat_Dot_Term (Some t), s private let close_branch (b : branch) : Tot R.branch = let (pat, t) = b in let pat, s = close_pat pat [] in let t' = subst_term s t in (pat, t') private let open_match_returns_ascription (mra : R.match_returns_ascription) : Tac match_returns_ascription = let (b, (ct, topt, use_eq)) = mra in let nb = open_binder b in let ct = match ct with | Inl t -> Inl (open_term_with b nb t) | Inr c -> let c = inspect_comp c in let c = open_comp_with b nb c in Inr c in let topt = match topt with | None -> None | Some t -> Some (open_term_with b nb t) in (nb, (ct, topt, use_eq)) private let close_match_returns_ascription (mra : match_returns_ascription) : R.match_returns_ascription = let (nb, (ct, topt, use_eq)) = mra in let b = close_binder nb in // FIXME: all this is repeating the close_binder work, for no good reason let ct = match ct with | Inl t -> Inl (snd (close_term nb t)) | Inr c -> let _, c = close_comp nb c in let c = pack_comp c in Inr c in let topt = match topt with | None -> None | Some t -> Some (snd (close_term nb t)) in (b, (ct, topt, use_eq)) private let open_view (tv:term_view) : Tac named_term_view = match tv with (* Nothing interesting *) | RD.Tv_Var v -> Tv_Var (inspect_namedv v) | RD.Tv_BVar v -> Tv_BVar (inspect_bv v) | RD.Tv_FVar v -> Tv_FVar v | RD.Tv_UInst v us -> Tv_UInst v us | RD.Tv_App hd a -> Tv_App hd a | RD.Tv_Type u -> Tv_Type u | RD.Tv_Const c -> Tv_Const c | RD.Tv_Uvar n ctx_uvar_and_subst -> Tv_Uvar n ctx_uvar_and_subst | RD.Tv_AscribedT e t tac use_eq -> Tv_AscribedT e t tac use_eq | RD.Tv_AscribedC e c tac use_eq -> Tv_AscribedC e (inspect_comp c) tac use_eq | RD.Tv_Unknown -> Tv_Unknown | RD.Tv_Unsupp -> Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | RD.Tv_Abs b body -> let nb, body = open_term b body in Tv_Abs nb body | RD.Tv_Arrow b c -> let nb, c = open_comp b (inspect_comp c) in Tv_Arrow nb c | RD.Tv_Refine b ref -> let nb, ref = open_term_simple b ref in Tv_Refine nb ref | RD.Tv_Let recf attrs b def body -> let nb, body = open_term_simple b body in let def = if recf then subst_term [DB 0 (r_binder_to_namedv nb)] def else def in Tv_Let recf attrs nb def body | RD.Tv_Match scrutinee ret brs -> let brs = map open_branch brs in let ret = map_opt open_match_returns_ascription ret in Tv_Match scrutinee ret brs private let close_view (tv : named_term_view) : Tot term_view = match tv with (* Nothing interesting *) | Tv_Var v -> RD.Tv_Var (pack_namedv v) | Tv_BVar v -> RD.Tv_BVar (pack_bv v) | Tv_FVar v -> RD.Tv_FVar v | Tv_UInst v us -> RD.Tv_UInst v us | Tv_App hd a -> RD.Tv_App hd a | Tv_Type u -> RD.Tv_Type u | Tv_Const c -> RD.Tv_Const c | Tv_Uvar n ctx_uvar_and_subst -> RD.Tv_Uvar n ctx_uvar_and_subst | Tv_AscribedT e t tac use_eq -> RD.Tv_AscribedT e t tac use_eq | Tv_AscribedC e c tac use_eq -> RD.Tv_AscribedC e (pack_comp c) tac use_eq | Tv_Unknown -> RD.Tv_Unknown | Tv_Unsupp -> RD.Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | Tv_Abs nb body -> let b, body = close_term nb body in RD.Tv_Abs b body | Tv_Arrow nb c -> let b, c = close_comp nb c in let c = pack_comp c in RD.Tv_Arrow b c | Tv_Refine nb ref -> let b, ref = close_term_simple nb ref in RD.Tv_Refine b ref | Tv_Let recf attrs nb def body -> let def = if recf then subst_term [NM (r_binder_to_namedv nb) 0] def else def in let b, body = close_term_simple nb body in RD.Tv_Let recf attrs b def body | Tv_Match scrutinee ret brs -> let brs = List.Tot.map close_branch brs in (* NOTE: this used to use FStar.Option.mapTot, but that brings in way too many dependencies. *) let ret = match ret with | None -> None | Some asc -> Some (close_match_returns_ascription asc) in RD.Tv_Match scrutinee ret brs [@@plugin; coercion] let inspect (t:term) : Tac named_term_view = let t = compress t in let tv = inspect_ln t in open_view tv
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
tv: FStar.Tactics.NamedView.named_term_view -> FStar.Tactics.NamedView.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.named_term_view", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.term_view", "FStar.Tactics.NamedView.close_view", "FStar.Tactics.NamedView.term" ]
[]
false
false
false
true
false
let pack (tv: named_term_view) : Tot term =
let tv = close_view tv in pack_ln tv
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_univ_s
val close_univ_s (us: list univ_name) : list R.univ_name & subst_t
val close_univ_s (us: list univ_name) : list R.univ_name & subst_t
let close_univ_s (us : list univ_name) : list R.univ_name & subst_t = let n = List.Tot.length us in let us = List.Tot.map (fun i -> pack_ident i) us in let s = List.Tot.mapi (fun i u -> UD u (n-i-1)) us in us, s
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 531, "start_col": 0, "start_line": 527 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t private let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'') private let rec close_term_n_simple (bs : list simple_binder) (t : term) : list R.simple_binder & term = match bs with | [] -> ([], t) | b::bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b'::bs', t'') private let rec open_pat (p : R.pattern) (s : subst_t) : Tac (pattern & subst_t) = match p with | R.Pat_Constant c -> Pat_Constant {c=c}, s | R.Pat_Var ssort n -> let sort = unseal ssort in let sort = subst_term s sort in let nvv : namedv = { uniq = fresh(); sort = seal sort; ppname = n; } in let nv = pack_namedv nvv in Pat_Var {v=nvv; sort=seal sort}, (DB 0 nv) :: shift_subst 1 s | R.Pat_Cons head univs subpats -> let subpats, s = fold_left (fun (pats,s) (pat,b) -> let pat, s' = open_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in Pat_Cons {head=head; univs=univs; subpats=subpats}, s | R.Pat_Dot_Term None -> Pat_Dot_Term {t=None}, s | R.Pat_Dot_Term (Some t) -> let t = subst_term s t in Pat_Dot_Term {t=Some t}, s private let open_branch (b : R.branch) : Tac branch = let (pat, t) = b in let pat, s = open_pat pat [] in let t' = subst_term s t in (pat, t') private let rec close_pat (p : pattern) (s : subst_t) : Tot (R.pattern & subst_t) = match p with | Pat_Constant {c} -> R.Pat_Constant c, s | Pat_Var {v; sort} -> let nv = pack_namedv v in (* NOTE: we cannot do anything on the sort wihtout going into TAC. Need a sealed_bind. *) //let sort = unseal sort in //let sort = subst_term s sort in //let sort = seal sort in let s = (NM nv 0) :: shift_subst 1 s in R.Pat_Var sort v.ppname, s | Pat_Cons {head; univs; subpats} -> let subpats, s = List.Tot.fold_left (fun (pats,s) (pat,b) -> assume(pat << p); let pat, s' = close_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in R.Pat_Cons head univs subpats, s | Pat_Dot_Term {t=None} -> R.Pat_Dot_Term None, s | Pat_Dot_Term {t=Some t} -> let t = subst_term s t in R.Pat_Dot_Term (Some t), s private let close_branch (b : branch) : Tot R.branch = let (pat, t) = b in let pat, s = close_pat pat [] in let t' = subst_term s t in (pat, t') private let open_match_returns_ascription (mra : R.match_returns_ascription) : Tac match_returns_ascription = let (b, (ct, topt, use_eq)) = mra in let nb = open_binder b in let ct = match ct with | Inl t -> Inl (open_term_with b nb t) | Inr c -> let c = inspect_comp c in let c = open_comp_with b nb c in Inr c in let topt = match topt with | None -> None | Some t -> Some (open_term_with b nb t) in (nb, (ct, topt, use_eq)) private let close_match_returns_ascription (mra : match_returns_ascription) : R.match_returns_ascription = let (nb, (ct, topt, use_eq)) = mra in let b = close_binder nb in // FIXME: all this is repeating the close_binder work, for no good reason let ct = match ct with | Inl t -> Inl (snd (close_term nb t)) | Inr c -> let _, c = close_comp nb c in let c = pack_comp c in Inr c in let topt = match topt with | None -> None | Some t -> Some (snd (close_term nb t)) in (b, (ct, topt, use_eq)) private let open_view (tv:term_view) : Tac named_term_view = match tv with (* Nothing interesting *) | RD.Tv_Var v -> Tv_Var (inspect_namedv v) | RD.Tv_BVar v -> Tv_BVar (inspect_bv v) | RD.Tv_FVar v -> Tv_FVar v | RD.Tv_UInst v us -> Tv_UInst v us | RD.Tv_App hd a -> Tv_App hd a | RD.Tv_Type u -> Tv_Type u | RD.Tv_Const c -> Tv_Const c | RD.Tv_Uvar n ctx_uvar_and_subst -> Tv_Uvar n ctx_uvar_and_subst | RD.Tv_AscribedT e t tac use_eq -> Tv_AscribedT e t tac use_eq | RD.Tv_AscribedC e c tac use_eq -> Tv_AscribedC e (inspect_comp c) tac use_eq | RD.Tv_Unknown -> Tv_Unknown | RD.Tv_Unsupp -> Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | RD.Tv_Abs b body -> let nb, body = open_term b body in Tv_Abs nb body | RD.Tv_Arrow b c -> let nb, c = open_comp b (inspect_comp c) in Tv_Arrow nb c | RD.Tv_Refine b ref -> let nb, ref = open_term_simple b ref in Tv_Refine nb ref | RD.Tv_Let recf attrs b def body -> let nb, body = open_term_simple b body in let def = if recf then subst_term [DB 0 (r_binder_to_namedv nb)] def else def in Tv_Let recf attrs nb def body | RD.Tv_Match scrutinee ret brs -> let brs = map open_branch brs in let ret = map_opt open_match_returns_ascription ret in Tv_Match scrutinee ret brs private let close_view (tv : named_term_view) : Tot term_view = match tv with (* Nothing interesting *) | Tv_Var v -> RD.Tv_Var (pack_namedv v) | Tv_BVar v -> RD.Tv_BVar (pack_bv v) | Tv_FVar v -> RD.Tv_FVar v | Tv_UInst v us -> RD.Tv_UInst v us | Tv_App hd a -> RD.Tv_App hd a | Tv_Type u -> RD.Tv_Type u | Tv_Const c -> RD.Tv_Const c | Tv_Uvar n ctx_uvar_and_subst -> RD.Tv_Uvar n ctx_uvar_and_subst | Tv_AscribedT e t tac use_eq -> RD.Tv_AscribedT e t tac use_eq | Tv_AscribedC e c tac use_eq -> RD.Tv_AscribedC e (pack_comp c) tac use_eq | Tv_Unknown -> RD.Tv_Unknown | Tv_Unsupp -> RD.Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | Tv_Abs nb body -> let b, body = close_term nb body in RD.Tv_Abs b body | Tv_Arrow nb c -> let b, c = close_comp nb c in let c = pack_comp c in RD.Tv_Arrow b c | Tv_Refine nb ref -> let b, ref = close_term_simple nb ref in RD.Tv_Refine b ref | Tv_Let recf attrs nb def body -> let def = if recf then subst_term [NM (r_binder_to_namedv nb) 0] def else def in let b, body = close_term_simple nb body in RD.Tv_Let recf attrs b def body | Tv_Match scrutinee ret brs -> let brs = List.Tot.map close_branch brs in (* NOTE: this used to use FStar.Option.mapTot, but that brings in way too many dependencies. *) let ret = match ret with | None -> None | Some asc -> Some (close_match_returns_ascription asc) in RD.Tv_Match scrutinee ret brs [@@plugin; coercion] let inspect (t:term) : Tac named_term_view = let t = compress t in let tv = inspect_ln t in open_view tv [@@plugin; coercion] let pack (tv:named_term_view) : Tot term = let tv = close_view tv in pack_ln tv private let open_univ_s (us : list R.univ_name) : Tac (list univ_name & subst_t) = let n = List.Tot.length us in let s = mapi (fun i u -> UN (n-1-i) (R.pack_universe (R.Uv_Name u))) us in Util.map (fun i -> inspect_ident i) us, s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
us: Prims.list FStar.Tactics.NamedView.univ_name -> Prims.list FStar.Stubs.Reflection.Types.univ_name * FStar.Stubs.Syntax.Syntax.subst_t
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "FStar.Tactics.NamedView.univ_name", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.Types.univ_name", "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.List.Tot.Base.mapi", "FStar.Stubs.Reflection.Types.ident", "Prims.int", "FStar.Stubs.Syntax.Syntax.UD", "Prims.op_Subtraction", "FStar.List.Tot.Base.map", "FStar.Stubs.Reflection.V2.Data.ident_view", "FStar.Stubs.Reflection.V2.Builtins.pack_ident", "Prims.nat", "FStar.List.Tot.Base.length", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
true
false
let close_univ_s (us: list univ_name) : list R.univ_name & subst_t =
let n = List.Tot.length us in let us = List.Tot.map (fun i -> pack_ident i) us in let s = List.Tot.mapi (fun i u -> UD u (n - i - 1)) us in us, s
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_term_simple
val close_term_simple (b: simple_binder) (t: term) : R.simple_binder & term
val close_term_simple (b: simple_binder) (t: term) : R.simple_binder & term
let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 215, "start_col": 0, "start_line": 209 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Tactics.NamedView.simple_binder -> t: FStar.Tactics.NamedView.term -> FStar.Stubs.Reflection.V2.Data.simple_binder * FStar.Tactics.NamedView.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.simple_binder", "FStar.Tactics.NamedView.term", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.simple_binder", "Prims.unit", "FStar.Stubs.Reflection.V2.Builtins.inspect_pack_binder", "FStar.Stubs.Reflection.Types.binder", "FStar.Stubs.Reflection.V2.Builtins.pack_binder", "FStar.Stubs.Reflection.V2.Data.binder_view", "FStar.Stubs.Reflection.V2.Data.Mkbinder_view", "FStar.Tactics.NamedView.__proj__Mkbinder__item__sort", "FStar.Tactics.NamedView.__proj__Mkbinder__item__qual", "FStar.Tactics.NamedView.__proj__Mkbinder__item__attrs", "FStar.Tactics.NamedView.__proj__Mkbinder__item__ppname", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Stubs.Syntax.Syntax.NM", "Prims.Nil", "FStar.Stubs.Reflection.Types.namedv", "FStar.Tactics.NamedView.r_binder_to_namedv", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
true
false
let close_term_simple (b: simple_binder) (t: term) : R.simple_binder & term =
let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv:binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t')
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_comp_simple
val close_comp_simple (b: simple_binder) (t: comp) : R.simple_binder & comp
val close_comp_simple (b: simple_binder) (t: comp) : R.simple_binder & comp
let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 223, "start_col": 0, "start_line": 217 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Tactics.NamedView.simple_binder -> t: FStar.Tactics.NamedView.comp -> FStar.Stubs.Reflection.V2.Data.simple_binder * FStar.Tactics.NamedView.comp
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.simple_binder", "FStar.Tactics.NamedView.comp", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.simple_binder", "Prims.unit", "FStar.Stubs.Reflection.V2.Builtins.inspect_pack_binder", "FStar.Stubs.Reflection.Types.binder", "FStar.Stubs.Reflection.V2.Builtins.pack_binder", "FStar.Stubs.Reflection.V2.Data.binder_view", "FStar.Stubs.Reflection.V2.Data.Mkbinder_view", "FStar.Tactics.NamedView.__proj__Mkbinder__item__sort", "FStar.Tactics.NamedView.__proj__Mkbinder__item__qual", "FStar.Tactics.NamedView.__proj__Mkbinder__item__attrs", "FStar.Tactics.NamedView.__proj__Mkbinder__item__ppname", "FStar.Tactics.NamedView.subst_comp", "Prims.Cons", "FStar.Stubs.Syntax.Syntax.subst_elt", "FStar.Stubs.Syntax.Syntax.NM", "Prims.Nil", "FStar.Stubs.Reflection.Types.namedv", "FStar.Tactics.NamedView.r_binder_to_namedv", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
true
false
let close_comp_simple (b: simple_binder) (t: comp) : R.simple_binder & comp =
let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv:binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t')
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.subst_r_binders
val subst_r_binders (s: subst_t) (bs: list R.binder) : list R.binder
val subst_r_binders (s: subst_t) (bs: list R.binder) : list R.binder
let subst_r_binders (s:subst_t) (bs : list R.binder) : list R.binder = List.Tot.mapi (fun i b -> r_subst_binder_sort (shift_subst i s) b) bs
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 71, "end_line": 551, "start_col": 0, "start_line": 550 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t private let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'') private let rec close_term_n_simple (bs : list simple_binder) (t : term) : list R.simple_binder & term = match bs with | [] -> ([], t) | b::bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b'::bs', t'') private let rec open_pat (p : R.pattern) (s : subst_t) : Tac (pattern & subst_t) = match p with | R.Pat_Constant c -> Pat_Constant {c=c}, s | R.Pat_Var ssort n -> let sort = unseal ssort in let sort = subst_term s sort in let nvv : namedv = { uniq = fresh(); sort = seal sort; ppname = n; } in let nv = pack_namedv nvv in Pat_Var {v=nvv; sort=seal sort}, (DB 0 nv) :: shift_subst 1 s | R.Pat_Cons head univs subpats -> let subpats, s = fold_left (fun (pats,s) (pat,b) -> let pat, s' = open_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in Pat_Cons {head=head; univs=univs; subpats=subpats}, s | R.Pat_Dot_Term None -> Pat_Dot_Term {t=None}, s | R.Pat_Dot_Term (Some t) -> let t = subst_term s t in Pat_Dot_Term {t=Some t}, s private let open_branch (b : R.branch) : Tac branch = let (pat, t) = b in let pat, s = open_pat pat [] in let t' = subst_term s t in (pat, t') private let rec close_pat (p : pattern) (s : subst_t) : Tot (R.pattern & subst_t) = match p with | Pat_Constant {c} -> R.Pat_Constant c, s | Pat_Var {v; sort} -> let nv = pack_namedv v in (* NOTE: we cannot do anything on the sort wihtout going into TAC. Need a sealed_bind. *) //let sort = unseal sort in //let sort = subst_term s sort in //let sort = seal sort in let s = (NM nv 0) :: shift_subst 1 s in R.Pat_Var sort v.ppname, s | Pat_Cons {head; univs; subpats} -> let subpats, s = List.Tot.fold_left (fun (pats,s) (pat,b) -> assume(pat << p); let pat, s' = close_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in R.Pat_Cons head univs subpats, s | Pat_Dot_Term {t=None} -> R.Pat_Dot_Term None, s | Pat_Dot_Term {t=Some t} -> let t = subst_term s t in R.Pat_Dot_Term (Some t), s private let close_branch (b : branch) : Tot R.branch = let (pat, t) = b in let pat, s = close_pat pat [] in let t' = subst_term s t in (pat, t') private let open_match_returns_ascription (mra : R.match_returns_ascription) : Tac match_returns_ascription = let (b, (ct, topt, use_eq)) = mra in let nb = open_binder b in let ct = match ct with | Inl t -> Inl (open_term_with b nb t) | Inr c -> let c = inspect_comp c in let c = open_comp_with b nb c in Inr c in let topt = match topt with | None -> None | Some t -> Some (open_term_with b nb t) in (nb, (ct, topt, use_eq)) private let close_match_returns_ascription (mra : match_returns_ascription) : R.match_returns_ascription = let (nb, (ct, topt, use_eq)) = mra in let b = close_binder nb in // FIXME: all this is repeating the close_binder work, for no good reason let ct = match ct with | Inl t -> Inl (snd (close_term nb t)) | Inr c -> let _, c = close_comp nb c in let c = pack_comp c in Inr c in let topt = match topt with | None -> None | Some t -> Some (snd (close_term nb t)) in (b, (ct, topt, use_eq)) private let open_view (tv:term_view) : Tac named_term_view = match tv with (* Nothing interesting *) | RD.Tv_Var v -> Tv_Var (inspect_namedv v) | RD.Tv_BVar v -> Tv_BVar (inspect_bv v) | RD.Tv_FVar v -> Tv_FVar v | RD.Tv_UInst v us -> Tv_UInst v us | RD.Tv_App hd a -> Tv_App hd a | RD.Tv_Type u -> Tv_Type u | RD.Tv_Const c -> Tv_Const c | RD.Tv_Uvar n ctx_uvar_and_subst -> Tv_Uvar n ctx_uvar_and_subst | RD.Tv_AscribedT e t tac use_eq -> Tv_AscribedT e t tac use_eq | RD.Tv_AscribedC e c tac use_eq -> Tv_AscribedC e (inspect_comp c) tac use_eq | RD.Tv_Unknown -> Tv_Unknown | RD.Tv_Unsupp -> Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | RD.Tv_Abs b body -> let nb, body = open_term b body in Tv_Abs nb body | RD.Tv_Arrow b c -> let nb, c = open_comp b (inspect_comp c) in Tv_Arrow nb c | RD.Tv_Refine b ref -> let nb, ref = open_term_simple b ref in Tv_Refine nb ref | RD.Tv_Let recf attrs b def body -> let nb, body = open_term_simple b body in let def = if recf then subst_term [DB 0 (r_binder_to_namedv nb)] def else def in Tv_Let recf attrs nb def body | RD.Tv_Match scrutinee ret brs -> let brs = map open_branch brs in let ret = map_opt open_match_returns_ascription ret in Tv_Match scrutinee ret brs private let close_view (tv : named_term_view) : Tot term_view = match tv with (* Nothing interesting *) | Tv_Var v -> RD.Tv_Var (pack_namedv v) | Tv_BVar v -> RD.Tv_BVar (pack_bv v) | Tv_FVar v -> RD.Tv_FVar v | Tv_UInst v us -> RD.Tv_UInst v us | Tv_App hd a -> RD.Tv_App hd a | Tv_Type u -> RD.Tv_Type u | Tv_Const c -> RD.Tv_Const c | Tv_Uvar n ctx_uvar_and_subst -> RD.Tv_Uvar n ctx_uvar_and_subst | Tv_AscribedT e t tac use_eq -> RD.Tv_AscribedT e t tac use_eq | Tv_AscribedC e c tac use_eq -> RD.Tv_AscribedC e (pack_comp c) tac use_eq | Tv_Unknown -> RD.Tv_Unknown | Tv_Unsupp -> RD.Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | Tv_Abs nb body -> let b, body = close_term nb body in RD.Tv_Abs b body | Tv_Arrow nb c -> let b, c = close_comp nb c in let c = pack_comp c in RD.Tv_Arrow b c | Tv_Refine nb ref -> let b, ref = close_term_simple nb ref in RD.Tv_Refine b ref | Tv_Let recf attrs nb def body -> let def = if recf then subst_term [NM (r_binder_to_namedv nb) 0] def else def in let b, body = close_term_simple nb body in RD.Tv_Let recf attrs b def body | Tv_Match scrutinee ret brs -> let brs = List.Tot.map close_branch brs in (* NOTE: this used to use FStar.Option.mapTot, but that brings in way too many dependencies. *) let ret = match ret with | None -> None | Some asc -> Some (close_match_returns_ascription asc) in RD.Tv_Match scrutinee ret brs [@@plugin; coercion] let inspect (t:term) : Tac named_term_view = let t = compress t in let tv = inspect_ln t in open_view tv [@@plugin; coercion] let pack (tv:named_term_view) : Tot term = let tv = close_view tv in pack_ln tv private let open_univ_s (us : list R.univ_name) : Tac (list univ_name & subst_t) = let n = List.Tot.length us in let s = mapi (fun i u -> UN (n-1-i) (R.pack_universe (R.Uv_Name u))) us in Util.map (fun i -> inspect_ident i) us, s private let close_univ_s (us : list univ_name) : list R.univ_name & subst_t = let n = List.Tot.length us in let us = List.Tot.map (fun i -> pack_ident i) us in let s = List.Tot.mapi (fun i u -> UD u (n-i-1)) us in us, s private let open_lb (lb : R.letbinding) : Tac letbinding = let {lb_fv; lb_us; lb_typ; lb_def} = inspect_lb lb in let lb_us, s = open_univ_s lb_us in let lb_typ = subst_term s lb_typ in let lb_def = subst_term s lb_def in { lb_fv; lb_us; lb_typ; lb_def } private let close_lb (lb : letbinding) : R.letbinding = let {lb_fv; lb_us; lb_typ; lb_def} = lb in let lb_us, s = close_univ_s lb_us in let lb_typ = subst_term s lb_typ in let lb_def = subst_term s lb_def in pack_lb { lb_fv; lb_us; lb_typ; lb_def }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Stubs.Syntax.Syntax.subst_t -> bs: Prims.list FStar.Stubs.Reflection.Types.binder -> Prims.list FStar.Stubs.Reflection.Types.binder
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Syntax.Syntax.subst_t", "Prims.list", "FStar.Stubs.Reflection.Types.binder", "FStar.List.Tot.Base.mapi", "Prims.int", "FStar.Tactics.NamedView.r_subst_binder_sort", "FStar.Reflection.V2.Derived.shift_subst" ]
[]
false
false
false
true
false
let subst_r_binders (s: subst_t) (bs: list R.binder) : list R.binder =
List.Tot.mapi (fun i b -> r_subst_binder_sort (shift_subst i s) b) bs
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_lb
val close_lb (lb: letbinding) : R.letbinding
val close_lb (lb: letbinding) : R.letbinding
let close_lb (lb : letbinding) : R.letbinding = let {lb_fv; lb_us; lb_typ; lb_def} = lb in let lb_us, s = close_univ_s lb_us in let lb_typ = subst_term s lb_typ in let lb_def = subst_term s lb_def in pack_lb { lb_fv; lb_us; lb_typ; lb_def }
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 547, "start_col": 0, "start_line": 542 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t private let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'') private let rec close_term_n_simple (bs : list simple_binder) (t : term) : list R.simple_binder & term = match bs with | [] -> ([], t) | b::bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b'::bs', t'') private let rec open_pat (p : R.pattern) (s : subst_t) : Tac (pattern & subst_t) = match p with | R.Pat_Constant c -> Pat_Constant {c=c}, s | R.Pat_Var ssort n -> let sort = unseal ssort in let sort = subst_term s sort in let nvv : namedv = { uniq = fresh(); sort = seal sort; ppname = n; } in let nv = pack_namedv nvv in Pat_Var {v=nvv; sort=seal sort}, (DB 0 nv) :: shift_subst 1 s | R.Pat_Cons head univs subpats -> let subpats, s = fold_left (fun (pats,s) (pat,b) -> let pat, s' = open_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in Pat_Cons {head=head; univs=univs; subpats=subpats}, s | R.Pat_Dot_Term None -> Pat_Dot_Term {t=None}, s | R.Pat_Dot_Term (Some t) -> let t = subst_term s t in Pat_Dot_Term {t=Some t}, s private let open_branch (b : R.branch) : Tac branch = let (pat, t) = b in let pat, s = open_pat pat [] in let t' = subst_term s t in (pat, t') private let rec close_pat (p : pattern) (s : subst_t) : Tot (R.pattern & subst_t) = match p with | Pat_Constant {c} -> R.Pat_Constant c, s | Pat_Var {v; sort} -> let nv = pack_namedv v in (* NOTE: we cannot do anything on the sort wihtout going into TAC. Need a sealed_bind. *) //let sort = unseal sort in //let sort = subst_term s sort in //let sort = seal sort in let s = (NM nv 0) :: shift_subst 1 s in R.Pat_Var sort v.ppname, s | Pat_Cons {head; univs; subpats} -> let subpats, s = List.Tot.fold_left (fun (pats,s) (pat,b) -> assume(pat << p); let pat, s' = close_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in R.Pat_Cons head univs subpats, s | Pat_Dot_Term {t=None} -> R.Pat_Dot_Term None, s | Pat_Dot_Term {t=Some t} -> let t = subst_term s t in R.Pat_Dot_Term (Some t), s private let close_branch (b : branch) : Tot R.branch = let (pat, t) = b in let pat, s = close_pat pat [] in let t' = subst_term s t in (pat, t') private let open_match_returns_ascription (mra : R.match_returns_ascription) : Tac match_returns_ascription = let (b, (ct, topt, use_eq)) = mra in let nb = open_binder b in let ct = match ct with | Inl t -> Inl (open_term_with b nb t) | Inr c -> let c = inspect_comp c in let c = open_comp_with b nb c in Inr c in let topt = match topt with | None -> None | Some t -> Some (open_term_with b nb t) in (nb, (ct, topt, use_eq)) private let close_match_returns_ascription (mra : match_returns_ascription) : R.match_returns_ascription = let (nb, (ct, topt, use_eq)) = mra in let b = close_binder nb in // FIXME: all this is repeating the close_binder work, for no good reason let ct = match ct with | Inl t -> Inl (snd (close_term nb t)) | Inr c -> let _, c = close_comp nb c in let c = pack_comp c in Inr c in let topt = match topt with | None -> None | Some t -> Some (snd (close_term nb t)) in (b, (ct, topt, use_eq)) private let open_view (tv:term_view) : Tac named_term_view = match tv with (* Nothing interesting *) | RD.Tv_Var v -> Tv_Var (inspect_namedv v) | RD.Tv_BVar v -> Tv_BVar (inspect_bv v) | RD.Tv_FVar v -> Tv_FVar v | RD.Tv_UInst v us -> Tv_UInst v us | RD.Tv_App hd a -> Tv_App hd a | RD.Tv_Type u -> Tv_Type u | RD.Tv_Const c -> Tv_Const c | RD.Tv_Uvar n ctx_uvar_and_subst -> Tv_Uvar n ctx_uvar_and_subst | RD.Tv_AscribedT e t tac use_eq -> Tv_AscribedT e t tac use_eq | RD.Tv_AscribedC e c tac use_eq -> Tv_AscribedC e (inspect_comp c) tac use_eq | RD.Tv_Unknown -> Tv_Unknown | RD.Tv_Unsupp -> Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | RD.Tv_Abs b body -> let nb, body = open_term b body in Tv_Abs nb body | RD.Tv_Arrow b c -> let nb, c = open_comp b (inspect_comp c) in Tv_Arrow nb c | RD.Tv_Refine b ref -> let nb, ref = open_term_simple b ref in Tv_Refine nb ref | RD.Tv_Let recf attrs b def body -> let nb, body = open_term_simple b body in let def = if recf then subst_term [DB 0 (r_binder_to_namedv nb)] def else def in Tv_Let recf attrs nb def body | RD.Tv_Match scrutinee ret brs -> let brs = map open_branch brs in let ret = map_opt open_match_returns_ascription ret in Tv_Match scrutinee ret brs private let close_view (tv : named_term_view) : Tot term_view = match tv with (* Nothing interesting *) | Tv_Var v -> RD.Tv_Var (pack_namedv v) | Tv_BVar v -> RD.Tv_BVar (pack_bv v) | Tv_FVar v -> RD.Tv_FVar v | Tv_UInst v us -> RD.Tv_UInst v us | Tv_App hd a -> RD.Tv_App hd a | Tv_Type u -> RD.Tv_Type u | Tv_Const c -> RD.Tv_Const c | Tv_Uvar n ctx_uvar_and_subst -> RD.Tv_Uvar n ctx_uvar_and_subst | Tv_AscribedT e t tac use_eq -> RD.Tv_AscribedT e t tac use_eq | Tv_AscribedC e c tac use_eq -> RD.Tv_AscribedC e (pack_comp c) tac use_eq | Tv_Unknown -> RD.Tv_Unknown | Tv_Unsupp -> RD.Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | Tv_Abs nb body -> let b, body = close_term nb body in RD.Tv_Abs b body | Tv_Arrow nb c -> let b, c = close_comp nb c in let c = pack_comp c in RD.Tv_Arrow b c | Tv_Refine nb ref -> let b, ref = close_term_simple nb ref in RD.Tv_Refine b ref | Tv_Let recf attrs nb def body -> let def = if recf then subst_term [NM (r_binder_to_namedv nb) 0] def else def in let b, body = close_term_simple nb body in RD.Tv_Let recf attrs b def body | Tv_Match scrutinee ret brs -> let brs = List.Tot.map close_branch brs in (* NOTE: this used to use FStar.Option.mapTot, but that brings in way too many dependencies. *) let ret = match ret with | None -> None | Some asc -> Some (close_match_returns_ascription asc) in RD.Tv_Match scrutinee ret brs [@@plugin; coercion] let inspect (t:term) : Tac named_term_view = let t = compress t in let tv = inspect_ln t in open_view tv [@@plugin; coercion] let pack (tv:named_term_view) : Tot term = let tv = close_view tv in pack_ln tv private let open_univ_s (us : list R.univ_name) : Tac (list univ_name & subst_t) = let n = List.Tot.length us in let s = mapi (fun i u -> UN (n-1-i) (R.pack_universe (R.Uv_Name u))) us in Util.map (fun i -> inspect_ident i) us, s private let close_univ_s (us : list univ_name) : list R.univ_name & subst_t = let n = List.Tot.length us in let us = List.Tot.map (fun i -> pack_ident i) us in let s = List.Tot.mapi (fun i u -> UD u (n-i-1)) us in us, s private let open_lb (lb : R.letbinding) : Tac letbinding = let {lb_fv; lb_us; lb_typ; lb_def} = inspect_lb lb in let lb_us, s = open_univ_s lb_us in let lb_typ = subst_term s lb_typ in let lb_def = subst_term s lb_def in { lb_fv; lb_us; lb_typ; lb_def }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
lb: FStar.Tactics.NamedView.letbinding -> FStar.Stubs.Reflection.Types.letbinding
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.letbinding", "FStar.Stubs.Reflection.Types.fv", "Prims.list", "FStar.Tactics.NamedView.univ_name", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.term", "FStar.Stubs.Reflection.Types.univ_name", "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Stubs.Reflection.V2.Builtins.pack_lb", "FStar.Stubs.Reflection.V2.Data.Mklb_view", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "FStar.Stubs.Reflection.Types.letbinding", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.NamedView.close_univ_s" ]
[]
false
false
false
true
false
let close_lb (lb: letbinding) : R.letbinding =
let { lb_fv = lb_fv ; lb_us = lb_us ; lb_typ = lb_typ ; lb_def = lb_def } = lb in let lb_us, s = close_univ_s lb_us in let lb_typ = subst_term s lb_typ in let lb_def = subst_term s lb_def in pack_lb ({ lb_fv = lb_fv; lb_us = lb_us; lb_typ = lb_typ; lb_def = lb_def })
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_lb
val open_lb (lb: R.letbinding) : Tac letbinding
val open_lb (lb: R.letbinding) : Tac letbinding
let open_lb (lb : R.letbinding) : Tac letbinding = let {lb_fv; lb_us; lb_typ; lb_def} = inspect_lb lb in let lb_us, s = open_univ_s lb_us in let lb_typ = subst_term s lb_typ in let lb_def = subst_term s lb_def in { lb_fv; lb_us; lb_typ; lb_def }
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 539, "start_col": 0, "start_line": 534 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t private let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'') private let rec close_term_n_simple (bs : list simple_binder) (t : term) : list R.simple_binder & term = match bs with | [] -> ([], t) | b::bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b'::bs', t'') private let rec open_pat (p : R.pattern) (s : subst_t) : Tac (pattern & subst_t) = match p with | R.Pat_Constant c -> Pat_Constant {c=c}, s | R.Pat_Var ssort n -> let sort = unseal ssort in let sort = subst_term s sort in let nvv : namedv = { uniq = fresh(); sort = seal sort; ppname = n; } in let nv = pack_namedv nvv in Pat_Var {v=nvv; sort=seal sort}, (DB 0 nv) :: shift_subst 1 s | R.Pat_Cons head univs subpats -> let subpats, s = fold_left (fun (pats,s) (pat,b) -> let pat, s' = open_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in Pat_Cons {head=head; univs=univs; subpats=subpats}, s | R.Pat_Dot_Term None -> Pat_Dot_Term {t=None}, s | R.Pat_Dot_Term (Some t) -> let t = subst_term s t in Pat_Dot_Term {t=Some t}, s private let open_branch (b : R.branch) : Tac branch = let (pat, t) = b in let pat, s = open_pat pat [] in let t' = subst_term s t in (pat, t') private let rec close_pat (p : pattern) (s : subst_t) : Tot (R.pattern & subst_t) = match p with | Pat_Constant {c} -> R.Pat_Constant c, s | Pat_Var {v; sort} -> let nv = pack_namedv v in (* NOTE: we cannot do anything on the sort wihtout going into TAC. Need a sealed_bind. *) //let sort = unseal sort in //let sort = subst_term s sort in //let sort = seal sort in let s = (NM nv 0) :: shift_subst 1 s in R.Pat_Var sort v.ppname, s | Pat_Cons {head; univs; subpats} -> let subpats, s = List.Tot.fold_left (fun (pats,s) (pat,b) -> assume(pat << p); let pat, s' = close_pat pat s in ((pat,b)::pats, s')) ([], s) subpats in let subpats = List.Tot.rev subpats in R.Pat_Cons head univs subpats, s | Pat_Dot_Term {t=None} -> R.Pat_Dot_Term None, s | Pat_Dot_Term {t=Some t} -> let t = subst_term s t in R.Pat_Dot_Term (Some t), s private let close_branch (b : branch) : Tot R.branch = let (pat, t) = b in let pat, s = close_pat pat [] in let t' = subst_term s t in (pat, t') private let open_match_returns_ascription (mra : R.match_returns_ascription) : Tac match_returns_ascription = let (b, (ct, topt, use_eq)) = mra in let nb = open_binder b in let ct = match ct with | Inl t -> Inl (open_term_with b nb t) | Inr c -> let c = inspect_comp c in let c = open_comp_with b nb c in Inr c in let topt = match topt with | None -> None | Some t -> Some (open_term_with b nb t) in (nb, (ct, topt, use_eq)) private let close_match_returns_ascription (mra : match_returns_ascription) : R.match_returns_ascription = let (nb, (ct, topt, use_eq)) = mra in let b = close_binder nb in // FIXME: all this is repeating the close_binder work, for no good reason let ct = match ct with | Inl t -> Inl (snd (close_term nb t)) | Inr c -> let _, c = close_comp nb c in let c = pack_comp c in Inr c in let topt = match topt with | None -> None | Some t -> Some (snd (close_term nb t)) in (b, (ct, topt, use_eq)) private let open_view (tv:term_view) : Tac named_term_view = match tv with (* Nothing interesting *) | RD.Tv_Var v -> Tv_Var (inspect_namedv v) | RD.Tv_BVar v -> Tv_BVar (inspect_bv v) | RD.Tv_FVar v -> Tv_FVar v | RD.Tv_UInst v us -> Tv_UInst v us | RD.Tv_App hd a -> Tv_App hd a | RD.Tv_Type u -> Tv_Type u | RD.Tv_Const c -> Tv_Const c | RD.Tv_Uvar n ctx_uvar_and_subst -> Tv_Uvar n ctx_uvar_and_subst | RD.Tv_AscribedT e t tac use_eq -> Tv_AscribedT e t tac use_eq | RD.Tv_AscribedC e c tac use_eq -> Tv_AscribedC e (inspect_comp c) tac use_eq | RD.Tv_Unknown -> Tv_Unknown | RD.Tv_Unsupp -> Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | RD.Tv_Abs b body -> let nb, body = open_term b body in Tv_Abs nb body | RD.Tv_Arrow b c -> let nb, c = open_comp b (inspect_comp c) in Tv_Arrow nb c | RD.Tv_Refine b ref -> let nb, ref = open_term_simple b ref in Tv_Refine nb ref | RD.Tv_Let recf attrs b def body -> let nb, body = open_term_simple b body in let def = if recf then subst_term [DB 0 (r_binder_to_namedv nb)] def else def in Tv_Let recf attrs nb def body | RD.Tv_Match scrutinee ret brs -> let brs = map open_branch brs in let ret = map_opt open_match_returns_ascription ret in Tv_Match scrutinee ret brs private let close_view (tv : named_term_view) : Tot term_view = match tv with (* Nothing interesting *) | Tv_Var v -> RD.Tv_Var (pack_namedv v) | Tv_BVar v -> RD.Tv_BVar (pack_bv v) | Tv_FVar v -> RD.Tv_FVar v | Tv_UInst v us -> RD.Tv_UInst v us | Tv_App hd a -> RD.Tv_App hd a | Tv_Type u -> RD.Tv_Type u | Tv_Const c -> RD.Tv_Const c | Tv_Uvar n ctx_uvar_and_subst -> RD.Tv_Uvar n ctx_uvar_and_subst | Tv_AscribedT e t tac use_eq -> RD.Tv_AscribedT e t tac use_eq | Tv_AscribedC e c tac use_eq -> RD.Tv_AscribedC e (pack_comp c) tac use_eq | Tv_Unknown -> RD.Tv_Unknown | Tv_Unsupp -> RD.Tv_Unsupp (* Below are the nodes that actually involve a binder. Open them and convert to named binders. *) | Tv_Abs nb body -> let b, body = close_term nb body in RD.Tv_Abs b body | Tv_Arrow nb c -> let b, c = close_comp nb c in let c = pack_comp c in RD.Tv_Arrow b c | Tv_Refine nb ref -> let b, ref = close_term_simple nb ref in RD.Tv_Refine b ref | Tv_Let recf attrs nb def body -> let def = if recf then subst_term [NM (r_binder_to_namedv nb) 0] def else def in let b, body = close_term_simple nb body in RD.Tv_Let recf attrs b def body | Tv_Match scrutinee ret brs -> let brs = List.Tot.map close_branch brs in (* NOTE: this used to use FStar.Option.mapTot, but that brings in way too many dependencies. *) let ret = match ret with | None -> None | Some asc -> Some (close_match_returns_ascription asc) in RD.Tv_Match scrutinee ret brs [@@plugin; coercion] let inspect (t:term) : Tac named_term_view = let t = compress t in let tv = inspect_ln t in open_view tv [@@plugin; coercion] let pack (tv:named_term_view) : Tot term = let tv = close_view tv in pack_ln tv private let open_univ_s (us : list R.univ_name) : Tac (list univ_name & subst_t) = let n = List.Tot.length us in let s = mapi (fun i u -> UN (n-1-i) (R.pack_universe (R.Uv_Name u))) us in Util.map (fun i -> inspect_ident i) us, s private let close_univ_s (us : list univ_name) : list R.univ_name & subst_t = let n = List.Tot.length us in let us = List.Tot.map (fun i -> pack_ident i) us in let s = List.Tot.mapi (fun i u -> UD u (n-i-1)) us in us, s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
lb: FStar.Stubs.Reflection.Types.letbinding -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.letbinding
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.letbinding", "FStar.Stubs.Reflection.Types.fv", "Prims.list", "FStar.Stubs.Reflection.Types.univ_name", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.NamedView.univ_name", "FStar.Stubs.Syntax.Syntax.subst_t", "FStar.Tactics.NamedView.Mkletbinding", "FStar.Stubs.Reflection.V2.Builtins.subst_term", "FStar.Tactics.NamedView.letbinding", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.NamedView.open_univ_s", "FStar.Stubs.Reflection.V2.Data.lb_view", "Prims.precedes", "FStar.Stubs.Reflection.V2.Builtins.inspect_lb" ]
[]
false
true
false
false
false
let open_lb (lb: R.letbinding) : Tac letbinding =
let { lb_fv = lb_fv ; lb_us = lb_us ; lb_typ = lb_typ ; lb_def = lb_def } = inspect_lb lb in let lb_us, s = open_univ_s lb_us in let lb_typ = subst_term s lb_typ in let lb_def = subst_term s lb_def in { lb_fv = lb_fv; lb_us = lb_us; lb_typ = lb_typ; lb_def = lb_def }
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.open_term_n_simple
val open_term_n_simple (bs: list R.simple_binder) (t: term) : Tac (list simple_binder & term)
val open_term_n_simple (bs: list R.simple_binder) (t: term) : Tac (list simple_binder & term)
let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 281, "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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
bs: Prims.list FStar.Stubs.Reflection.V2.Data.simple_binder -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.simple_binder * FStar.Tactics.NamedView.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Stubs.Reflection.V2.Data.simple_binder", "FStar.Tactics.NamedView.term", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.NamedView.simple_binder", "Prims.Nil", "FStar.Pervasives.Native.tuple2", "Prims.Cons", "FStar.Tactics.NamedView.open_term_simple", "FStar.Tactics.NamedView.open_term_n_simple" ]
[ "recursion" ]
false
true
false
false
false
let rec open_term_n_simple (bs: list R.simple_binder) (t: term) : Tac (list simple_binder & term) =
match bs with | [] -> ([], t) | b :: bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b' :: bs', t'')
false
FStar.Tactics.NamedView.fst
FStar.Tactics.NamedView.close_term_n_simple
val close_term_n_simple (bs: list simple_binder) (t: term) : list R.simple_binder & term
val close_term_n_simple (bs: list simple_binder) (t: term) : list R.simple_binder & term
let rec close_term_n_simple (bs : list simple_binder) (t : term) : list R.simple_binder & term = match bs with | [] -> ([], t) | b::bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b'::bs', t'')
{ "file_name": "ulib/FStar.Tactics.NamedView.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 290, "start_col": 0, "start_line": 284 }
(* 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.Tactics.NamedView (* inner let bindings not encoded, OK *) #set-options "--warn_error -242" (* This file is part of the tactics core, we open only what's needed. *) open FStar.Tactics.Effect open FStar.Tactics.Util open FStar.Stubs.Tactics.V2.Builtins exception LengthMismatch exception NotEnoughBinders (* We work with reflection V2. *) module R = FStar.Reflection.V2 module RD = FStar.Stubs.Reflection.V2.Data let open_universe_view (v:RD.universe_view) : named_universe_view = match v with | R.Uv_Zero -> Uv_Zero | R.Uv_Succ u -> Uv_Succ u | R.Uv_Max us -> Uv_Max us | R.Uv_BVar n -> Uv_BVar n | R.Uv_Name i -> Uv_Name (inspect_ident i) | R.Uv_Unif uvar -> Uv_Unif uvar | R.Uv_Unk -> Uv_Unk let inspect_universe (u:universe) : named_universe_view = let v = R.inspect_universe u in open_universe_view v let close_universe_view (v:named_universe_view) : R.universe_view = match v with | Uv_Zero -> R.Uv_Zero | Uv_Succ u -> R.Uv_Succ u | Uv_Max us -> R.Uv_Max us | Uv_BVar n -> R.Uv_BVar n | Uv_Name i -> R.Uv_Name (pack_ident i) | Uv_Unif uvar -> R.Uv_Unif uvar | Uv_Unk -> R.Uv_Unk let pack_universe (uv:named_universe_view) : universe = let uv = close_universe_view uv in R.pack_universe uv private let __binding_to_binder (bnd : binding) (b : R.binder) : binder = { ppname = bnd.ppname; uniq = bnd.uniq; sort = bnd.sort; qual = (inspect_binder b).qual; attrs = (inspect_binder b).attrs; } private let r_binder_to_namedv (b : binder) : R.namedv = pack_namedv { uniq = b.uniq; sort = seal b.sort; ppname = b.ppname; } private let open_binder (b : R.binder) : Tac binder = let n = fresh () in let bv = inspect_binder b in { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } private let close_binder (b : binder) : R.binder = pack_binder { sort = b.sort; qual = b.qual; ppname = b.ppname; attrs = b.attrs; } private let open_term_with (b : R.binder) (nb : binder) (t : term) : Tac term = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_term [DB 0 nv] t in t' private let open_term (b : R.binder) (t : term) : Tac (binder & term) = let bndr : binder = open_binder b in (bndr, open_term_with b bndr t) let subst_comp (s : subst_t) (c : comp) : comp = inspect_comp (R.subst_comp s (pack_comp c)) private let open_comp (b : R.binder) (t : comp) : Tac (binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_with (b : R.binder) (nb : binder) (c : comp) : Tac comp = let nv : R.namedv = pack_namedv { uniq = nb.uniq; sort = seal nb.sort; ppname = nb.ppname; } in let t' = subst_comp [DB 0 nv] c in t' (* FIXME: unfortunate duplication here. The effect means this proof cannot be done extrinsically. Can we add a refinement to the binder? *) private let open_term_simple (b : R.simple_binder) (t : term) : Tac (simple_binder & term) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_term [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') private let open_comp_simple (b : R.simple_binder) (t : comp) : Tac (simple_binder & comp) = let n = fresh () in let bv : binder_view = inspect_binder b in let nv : R.namedv = pack_namedv { uniq = n; sort = seal bv.sort; ppname = bv.ppname; } in let t' = subst_comp [DB 0 nv] t in let bndr : binder = { uniq = n; sort = bv.sort; ppname = bv.ppname; qual = bv.qual; attrs = bv.attrs; } in (bndr, t') (* This can be useful externally *) let close_term (b:binder) (t:term) : R.binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_comp (b:binder) (t:comp) : R.binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let b = pack_binder { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in (b, t') private let close_term_simple (b:simple_binder) (t:term) : R.simple_binder & term = let nv = r_binder_to_namedv b in let t' = subst_term [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let close_comp_simple (b:simple_binder) (t:comp) : R.simple_binder & comp = let nv = r_binder_to_namedv b in let t' = subst_comp [NM nv 0] t in let bv : binder_view = { sort = b.sort; ppname = b.ppname; qual = b.qual; attrs = b.attrs } in let b = pack_binder bv in inspect_pack_binder bv; (b, t') private let r_subst_binder_sort (s : subst_t) (b : R.binder) : R.binder = let v = inspect_binder b in let v = { v with sort = subst_term s v.sort } in pack_binder v let subst_binder_sort (s : subst_t) (b : binder) : binder = { b with sort = subst_term s b.sort } (* Can't define this inside open_term_n. See #2955 *) private let rec __open_term_n_aux (bs : list R.binder) (nbs : list binder) (s : subst_t) : Tac (list binder & subst_t) = match bs with | [] -> nbs, s | b::bs -> let b = r_subst_binder_sort s b in let b = open_binder b in let nv = r_binder_to_namedv b in __open_term_n_aux bs (b::nbs) (DB 0 nv :: shift_subst 1 s) private let open_term_n (bs : list R.binder) (t : term) : Tac (list binder & term) = let nbs, s = __open_term_n_aux bs [] [] in List.Tot.rev nbs, subst_term s t private let rec open_term_n_with (bs : list R.binder) (nbs : list binder) (t : term) : Tac term = match bs, nbs with | [], [] -> t | b::bs, nb::nbs -> let t' = open_term_n_with bs nbs t in let t'' = open_term_with b nb t' in t'' | _ -> raise LengthMismatch private let close_term_n (bs : list binder) (t : term) : list R.binder & term = let rec aux (bs : list binder) (cbs : list R.binder) (s : subst_t) : list R.binder & subst_t = match bs with | [] -> cbs, s | b::bs -> let b = subst_binder_sort s b in let nv = r_binder_to_namedv b in let b = close_binder b in aux bs (b::cbs) (NM nv 0 :: shift_subst 1 s) in let cbs, s = aux bs [] [] in List.Tot.rev cbs, subst_term s t private let rec open_term_n_simple (bs : list R.simple_binder) (t : term) : Tac (list simple_binder & term) = match bs with | [] -> ([], t) | b::bs -> let bs', t' = open_term_n_simple bs t in let b', t'' = open_term_simple b t' in (b'::bs', t'')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Reflection.V2.Data.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "FStar.Tactics.NamedView.fst" }
[ { "abbrev": true, "full_module": "FStar.Stubs.Reflection.V2.Data", "short_module": "RD" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
bs: Prims.list FStar.Tactics.NamedView.simple_binder -> t: FStar.Tactics.NamedView.term -> Prims.list FStar.Stubs.Reflection.V2.Data.simple_binder * FStar.Tactics.NamedView.term
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "FStar.Tactics.NamedView.simple_binder", "FStar.Tactics.NamedView.term", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V2.Data.simple_binder", "Prims.Nil", "Prims.Cons", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.NamedView.close_term_simple", "FStar.Tactics.NamedView.close_term_n_simple" ]
[ "recursion" ]
false
false
false
true
false
let rec close_term_n_simple (bs: list simple_binder) (t: term) : list R.simple_binder & term =
match bs with | [] -> ([], t) | b :: bs -> let bs', t' = close_term_n_simple bs t in let b', t'' = close_term_simple b t' in (b' :: bs', t'')
false