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
MiniParse.Tac.Base.fst
MiniParse.Tac.Base.tsplit
val tsplit : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
let tsplit () = T.split ()
{ "file_name": "examples/miniparse/MiniParse.Tac.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 134, "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 MiniParse.Tac.Base module T = FStar.Tactics.V2 module L = FStar.List.Tot let pack_nat (n: nat) : T.Tac T.term = T.pack (T.Tv_Const (T.C_Int n)) let rec app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv) = let ins = T.inspect t in if T.Tv_App? ins then let (T.Tv_App u v) = ins in let (x, l) = app_head_rev_tail u in (x, v :: l) else (t, []) let app_head_tail (t: T.term) : T.Tac (T.term * list T.argv) = let (x, l) = app_head_rev_tail t in (x, L.rev l) inline_for_extraction let ctest (v: bool) (test: bool) : Tot Type = squash (test == v) inline_for_extraction let mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t = if test then x1 () else x2 () let mk_if (test ty e_true e_false: T.term) : T.Tac T.term = let bt = T.fresh_binder (T.mk_app (`(ctest true)) [test, T.Q_Explicit]) in let bf = T.fresh_binder (T.mk_app (`(ctest false)) [test, T.Q_Explicit]) in let ft = T.pack (T.Tv_Abs bt e_true) in let ff = T.pack (T.Tv_Abs bf e_false) in T.mk_app (`(mk_if_t)) [ ty, T.Q_Implicit; test, T.Q_Explicit; ft, T.Q_Explicit; ff, T.Q_Explicit; ] let tfail (#a: Type) (s: Prims.string) : T.Tac a = T.debug ("Tactic failure: " ^ s); T.fail s let rec string_of_name (n: T.name) : Tot string = match n with | [] -> "" | [a] -> a | a :: b -> a ^ "." ^ string_of_name b let unfold_fv (t: T.fv) : T.Tac T.term = let env = T.cur_env () in let n = T.inspect_fv t in match T.lookup_typ env n with | Some s -> begin match T.inspect_sigelt s with | T.Sg_Let {isrec=false; lbs=[lb]} -> let nm = string_of_name n in T.debug ("Unfolded definition: " ^ nm); T.(lb.lb_def) | _ -> let nm = string_of_name n in tfail (nm ^ ": not a non-recursive let definition") end | _ -> tfail "Definition not found" let unfold_term (t: T.term) : T.Tac T.term = match T.inspect t with | T.Tv_FVar v -> unfold_fv v | _ -> tfail "Not a global variable" let tsuccess (s: string) : T.Tac unit = T.debug ("Checking success for: " ^ s); T.qed (); T.debug ("Success: " ^ s) let rec to_all_goals (t: unit -> T.Tac unit) : T.Tac unit = if T.ngoals () = 0 then () else let _ = T.divide 1 t (fun () -> to_all_goals t) in () let rec imm_solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit = T.first (List.Tot.append l [ (fun () -> T.trivial (); tsuccess "trivial" ); (fun () -> T.trefl (); tsuccess "reflexivity" ); (fun () -> T.assumption (); tsuccess "assumption" ); (fun () -> T.norm [delta; zeta; iota; primops]; T.trivial (); tsuccess "norm trivial" ); (fun () -> T.apply (`(FStar.Squash.return_squash)); to_all_goals (fun () -> imm_solve_goal l); tsuccess "return_squash imm_solve" ); ]) let tforall_intro () = T.forall_intro () let timplies_intro () = T.implies_intro ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "MiniParse.Tac.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Logic.split" ]
[]
false
true
false
false
false
let tsplit () =
T.split ()
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.in_bounds
val in_bounds : i: Prims.nat -> j: Prims.nat -> s: Pulse.Lib.HigherArray.array 'a -> Type0
let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 71, "end_line": 483, "start_col": 0, "start_line": 483 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i)
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.nat -> j: Prims.nat -> s: Pulse.Lib.HigherArray.array 'a -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Pulse.Lib.HigherArray.array", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Pulse.Lib.HigherArray.length" ]
[]
false
false
false
true
true
let in_bounds (i j: nat) (s: array 'a) =
squash (i <= j /\ j <= length s)
false
MiniParse.Tac.Base.fst
MiniParse.Tac.Base.timplies_intro
val timplies_intro : _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding
let timplies_intro () = T.implies_intro ()
{ "file_name": "examples/miniparse/MiniParse.Tac.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 132, "start_col": 0, "start_line": 132 }
(* 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 MiniParse.Tac.Base module T = FStar.Tactics.V2 module L = FStar.List.Tot let pack_nat (n: nat) : T.Tac T.term = T.pack (T.Tv_Const (T.C_Int n)) let rec app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv) = let ins = T.inspect t in if T.Tv_App? ins then let (T.Tv_App u v) = ins in let (x, l) = app_head_rev_tail u in (x, v :: l) else (t, []) let app_head_tail (t: T.term) : T.Tac (T.term * list T.argv) = let (x, l) = app_head_rev_tail t in (x, L.rev l) inline_for_extraction let ctest (v: bool) (test: bool) : Tot Type = squash (test == v) inline_for_extraction let mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t = if test then x1 () else x2 () let mk_if (test ty e_true e_false: T.term) : T.Tac T.term = let bt = T.fresh_binder (T.mk_app (`(ctest true)) [test, T.Q_Explicit]) in let bf = T.fresh_binder (T.mk_app (`(ctest false)) [test, T.Q_Explicit]) in let ft = T.pack (T.Tv_Abs bt e_true) in let ff = T.pack (T.Tv_Abs bf e_false) in T.mk_app (`(mk_if_t)) [ ty, T.Q_Implicit; test, T.Q_Explicit; ft, T.Q_Explicit; ff, T.Q_Explicit; ] let tfail (#a: Type) (s: Prims.string) : T.Tac a = T.debug ("Tactic failure: " ^ s); T.fail s let rec string_of_name (n: T.name) : Tot string = match n with | [] -> "" | [a] -> a | a :: b -> a ^ "." ^ string_of_name b let unfold_fv (t: T.fv) : T.Tac T.term = let env = T.cur_env () in let n = T.inspect_fv t in match T.lookup_typ env n with | Some s -> begin match T.inspect_sigelt s with | T.Sg_Let {isrec=false; lbs=[lb]} -> let nm = string_of_name n in T.debug ("Unfolded definition: " ^ nm); T.(lb.lb_def) | _ -> let nm = string_of_name n in tfail (nm ^ ": not a non-recursive let definition") end | _ -> tfail "Definition not found" let unfold_term (t: T.term) : T.Tac T.term = match T.inspect t with | T.Tv_FVar v -> unfold_fv v | _ -> tfail "Not a global variable" let tsuccess (s: string) : T.Tac unit = T.debug ("Checking success for: " ^ s); T.qed (); T.debug ("Success: " ^ s) let rec to_all_goals (t: unit -> T.Tac unit) : T.Tac unit = if T.ngoals () = 0 then () else let _ = T.divide 1 t (fun () -> to_all_goals t) in () let rec imm_solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit = T.first (List.Tot.append l [ (fun () -> T.trivial (); tsuccess "trivial" ); (fun () -> T.trefl (); tsuccess "reflexivity" ); (fun () -> T.assumption (); tsuccess "assumption" ); (fun () -> T.norm [delta; zeta; iota; primops]; T.trivial (); tsuccess "norm trivial" ); (fun () -> T.apply (`(FStar.Squash.return_squash)); to_all_goals (fun () -> imm_solve_goal l); tsuccess "return_squash imm_solve" ); ]) let tforall_intro () = T.forall_intro ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "MiniParse.Tac.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Tactics.Effect.Tac FStar.Tactics.NamedView.binding
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Logic.implies_intro", "FStar.Tactics.NamedView.binding" ]
[]
false
true
false
false
false
let timplies_intro () =
T.implies_intro ()
false
MiniParse.Tac.Base.fst
MiniParse.Tac.Base.tconclude
val tconclude: Prims.unit -> T.Tac unit
val tconclude: Prims.unit -> T.Tac unit
let tconclude () : T.Tac unit = tconclude_with []
{ "file_name": "examples/miniparse/MiniParse.Tac.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 191, "start_col": 0, "start_line": 191 }
(* 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 MiniParse.Tac.Base module T = FStar.Tactics.V2 module L = FStar.List.Tot let pack_nat (n: nat) : T.Tac T.term = T.pack (T.Tv_Const (T.C_Int n)) let rec app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv) = let ins = T.inspect t in if T.Tv_App? ins then let (T.Tv_App u v) = ins in let (x, l) = app_head_rev_tail u in (x, v :: l) else (t, []) let app_head_tail (t: T.term) : T.Tac (T.term * list T.argv) = let (x, l) = app_head_rev_tail t in (x, L.rev l) inline_for_extraction let ctest (v: bool) (test: bool) : Tot Type = squash (test == v) inline_for_extraction let mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t = if test then x1 () else x2 () let mk_if (test ty e_true e_false: T.term) : T.Tac T.term = let bt = T.fresh_binder (T.mk_app (`(ctest true)) [test, T.Q_Explicit]) in let bf = T.fresh_binder (T.mk_app (`(ctest false)) [test, T.Q_Explicit]) in let ft = T.pack (T.Tv_Abs bt e_true) in let ff = T.pack (T.Tv_Abs bf e_false) in T.mk_app (`(mk_if_t)) [ ty, T.Q_Implicit; test, T.Q_Explicit; ft, T.Q_Explicit; ff, T.Q_Explicit; ] let tfail (#a: Type) (s: Prims.string) : T.Tac a = T.debug ("Tactic failure: " ^ s); T.fail s let rec string_of_name (n: T.name) : Tot string = match n with | [] -> "" | [a] -> a | a :: b -> a ^ "." ^ string_of_name b let unfold_fv (t: T.fv) : T.Tac T.term = let env = T.cur_env () in let n = T.inspect_fv t in match T.lookup_typ env n with | Some s -> begin match T.inspect_sigelt s with | T.Sg_Let {isrec=false; lbs=[lb]} -> let nm = string_of_name n in T.debug ("Unfolded definition: " ^ nm); T.(lb.lb_def) | _ -> let nm = string_of_name n in tfail (nm ^ ": not a non-recursive let definition") end | _ -> tfail "Definition not found" let unfold_term (t: T.term) : T.Tac T.term = match T.inspect t with | T.Tv_FVar v -> unfold_fv v | _ -> tfail "Not a global variable" let tsuccess (s: string) : T.Tac unit = T.debug ("Checking success for: " ^ s); T.qed (); T.debug ("Success: " ^ s) let rec to_all_goals (t: unit -> T.Tac unit) : T.Tac unit = if T.ngoals () = 0 then () else let _ = T.divide 1 t (fun () -> to_all_goals t) in () let rec imm_solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit = T.first (List.Tot.append l [ (fun () -> T.trivial (); tsuccess "trivial" ); (fun () -> T.trefl (); tsuccess "reflexivity" ); (fun () -> T.assumption (); tsuccess "assumption" ); (fun () -> T.norm [delta; zeta; iota; primops]; T.trivial (); tsuccess "norm trivial" ); (fun () -> T.apply (`(FStar.Squash.return_squash)); to_all_goals (fun () -> imm_solve_goal l); tsuccess "return_squash imm_solve" ); ]) let tforall_intro () = T.forall_intro () let timplies_intro () = T.implies_intro () let tsplit () = T.split () let rec solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit = if T.ngoals () = 0 then () else begin begin if T.ngoals () > 1 then tfail "More than one goal here" else () end; begin match T.trytac tforall_intro with | Some _ -> T.debug ("Applied: forall_intro"); to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac timplies_intro with | Some _ -> T.debug ("Applied: implies_intro"); to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac tsplit with | Some _ -> let n = T.ngoals () in if n > 2 then tfail "There should be only at most 2 goals here" (* let _ = T.divide 2 (fun () -> to_all_goals solve_goal) (fun () -> to_all_goals T.tadmit) in () *) else to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac (fun () -> imm_solve_goal l) with | Some _ -> () | _ -> if T.debugging () then T.dump "MUST USE SMT FOR THIS ONE"; T.smt (); tsuccess "smt" end end end end end let rec tconclude_with (l: list (unit -> T.Tac unit)) : T.Tac unit = if T.ngoals () > 0 then begin if T.debugging () then T.dump "Some goals left"; let _ = T.divide 1 (fun () -> solve_goal l) (fun () -> tconclude_with l) in () end else T.debug "No goals left"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "MiniParse.Tac.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "MiniParse.Tac.Base.tconclude_with", "Prims.Nil" ]
[]
false
true
false
false
false
let tconclude () : T.Tac unit =
tconclude_with []
false
MiniParse.Tac.Base.fst
MiniParse.Tac.Base.tconclude_with
val tconclude_with (l: list (unit -> T.Tac unit)) : T.Tac unit
val tconclude_with (l: list (unit -> T.Tac unit)) : T.Tac unit
let rec tconclude_with (l: list (unit -> T.Tac unit)) : T.Tac unit = if T.ngoals () > 0 then begin if T.debugging () then T.dump "Some goals left"; let _ = T.divide 1 (fun () -> solve_goal l) (fun () -> tconclude_with l) in () end else T.debug "No goals left"
{ "file_name": "examples/miniparse/MiniParse.Tac.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 189, "start_col": 0, "start_line": 182 }
(* 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 MiniParse.Tac.Base module T = FStar.Tactics.V2 module L = FStar.List.Tot let pack_nat (n: nat) : T.Tac T.term = T.pack (T.Tv_Const (T.C_Int n)) let rec app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv) = let ins = T.inspect t in if T.Tv_App? ins then let (T.Tv_App u v) = ins in let (x, l) = app_head_rev_tail u in (x, v :: l) else (t, []) let app_head_tail (t: T.term) : T.Tac (T.term * list T.argv) = let (x, l) = app_head_rev_tail t in (x, L.rev l) inline_for_extraction let ctest (v: bool) (test: bool) : Tot Type = squash (test == v) inline_for_extraction let mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t = if test then x1 () else x2 () let mk_if (test ty e_true e_false: T.term) : T.Tac T.term = let bt = T.fresh_binder (T.mk_app (`(ctest true)) [test, T.Q_Explicit]) in let bf = T.fresh_binder (T.mk_app (`(ctest false)) [test, T.Q_Explicit]) in let ft = T.pack (T.Tv_Abs bt e_true) in let ff = T.pack (T.Tv_Abs bf e_false) in T.mk_app (`(mk_if_t)) [ ty, T.Q_Implicit; test, T.Q_Explicit; ft, T.Q_Explicit; ff, T.Q_Explicit; ] let tfail (#a: Type) (s: Prims.string) : T.Tac a = T.debug ("Tactic failure: " ^ s); T.fail s let rec string_of_name (n: T.name) : Tot string = match n with | [] -> "" | [a] -> a | a :: b -> a ^ "." ^ string_of_name b let unfold_fv (t: T.fv) : T.Tac T.term = let env = T.cur_env () in let n = T.inspect_fv t in match T.lookup_typ env n with | Some s -> begin match T.inspect_sigelt s with | T.Sg_Let {isrec=false; lbs=[lb]} -> let nm = string_of_name n in T.debug ("Unfolded definition: " ^ nm); T.(lb.lb_def) | _ -> let nm = string_of_name n in tfail (nm ^ ": not a non-recursive let definition") end | _ -> tfail "Definition not found" let unfold_term (t: T.term) : T.Tac T.term = match T.inspect t with | T.Tv_FVar v -> unfold_fv v | _ -> tfail "Not a global variable" let tsuccess (s: string) : T.Tac unit = T.debug ("Checking success for: " ^ s); T.qed (); T.debug ("Success: " ^ s) let rec to_all_goals (t: unit -> T.Tac unit) : T.Tac unit = if T.ngoals () = 0 then () else let _ = T.divide 1 t (fun () -> to_all_goals t) in () let rec imm_solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit = T.first (List.Tot.append l [ (fun () -> T.trivial (); tsuccess "trivial" ); (fun () -> T.trefl (); tsuccess "reflexivity" ); (fun () -> T.assumption (); tsuccess "assumption" ); (fun () -> T.norm [delta; zeta; iota; primops]; T.trivial (); tsuccess "norm trivial" ); (fun () -> T.apply (`(FStar.Squash.return_squash)); to_all_goals (fun () -> imm_solve_goal l); tsuccess "return_squash imm_solve" ); ]) let tforall_intro () = T.forall_intro () let timplies_intro () = T.implies_intro () let tsplit () = T.split () let rec solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit = if T.ngoals () = 0 then () else begin begin if T.ngoals () > 1 then tfail "More than one goal here" else () end; begin match T.trytac tforall_intro with | Some _ -> T.debug ("Applied: forall_intro"); to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac timplies_intro with | Some _ -> T.debug ("Applied: implies_intro"); to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac tsplit with | Some _ -> let n = T.ngoals () in if n > 2 then tfail "There should be only at most 2 goals here" (* let _ = T.divide 2 (fun () -> to_all_goals solve_goal) (fun () -> to_all_goals T.tadmit) in () *) else to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac (fun () -> imm_solve_goal l) with | Some _ -> () | _ -> if T.debugging () then T.dump "MUST USE SMT FOR THIS ONE"; T.smt (); tsuccess "smt" end end end end end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "MiniParse.Tac.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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
l: Prims.list (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "Prims.unit", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.V2.Derived.divide", "MiniParse.Tac.Base.solve_goal", "MiniParse.Tac.Base.tconclude_with", "FStar.Stubs.Tactics.V2.Builtins.dump", "Prims.bool", "FStar.Stubs.Tactics.V2.Builtins.debugging", "FStar.Tactics.V2.Derived.debug", "Prims.op_GreaterThan", "Prims.int", "FStar.Tactics.V2.Derived.ngoals" ]
[ "recursion" ]
false
true
false
false
false
let rec tconclude_with (l: list (unit -> T.Tac unit)) : T.Tac unit =
if T.ngoals () > 0 then (if T.debugging () then T.dump "Some goals left"; let _ = T.divide 1 (fun () -> solve_goal l) (fun () -> tconclude_with l) in ()) else T.debug "No goals left"
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.is_null_ptr
val is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt))
val is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt))
let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 24, "end_line": 61, "start_col": 0, "start_line": 57 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Pulse.Lib.HigherArray.ptr elt -> Prims.Pure Prims.bool
Prims.Pure
[]
[]
[ "Pulse.Lib.HigherArray.ptr", "Pulse.Lib.Core.is_pcm_ref_null", "Pulse.Lib.PCM.Array.carrier", "FStar.Ghost.hide", "Prims.nat", "FStar.SizeT.v", "FStar.Ghost.reveal", "FStar.SizeT.t", "Pulse.Lib.HigherArray.__proj__Mkptr__item__base_len", "Pulse.Lib.PCM.Array.pcm", "Pulse.Lib.HigherArray.__proj__Mkptr__item__base", "Prims.bool", "Prims.l_True", "Prims.l_iff", "Prims.eq2", "Pulse.Lib.HigherArray.null_ptr" ]
[]
false
false
false
false
false
let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) =
is_pcm_ref_null p.base
false
MiniParse.Tac.Base.fst
MiniParse.Tac.Base.according_to
val according_to (pol: T.guard_policy) (t: (unit -> T.Tac unit)) : T.Tac unit
val according_to (pol: T.guard_policy) (t: (unit -> T.Tac unit)) : T.Tac unit
let according_to (pol: T.guard_policy) (t: (unit -> T.Tac unit)) : T.Tac unit = match pol with | T.SMT -> to_all_goals T.smt | T.Drop -> to_all_goals T.tadmit | _ -> T.with_policy pol t
{ "file_name": "examples/miniparse/MiniParse.Tac.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 197, "start_col": 0, "start_line": 193 }
(* 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 MiniParse.Tac.Base module T = FStar.Tactics.V2 module L = FStar.List.Tot let pack_nat (n: nat) : T.Tac T.term = T.pack (T.Tv_Const (T.C_Int n)) let rec app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv) = let ins = T.inspect t in if T.Tv_App? ins then let (T.Tv_App u v) = ins in let (x, l) = app_head_rev_tail u in (x, v :: l) else (t, []) let app_head_tail (t: T.term) : T.Tac (T.term * list T.argv) = let (x, l) = app_head_rev_tail t in (x, L.rev l) inline_for_extraction let ctest (v: bool) (test: bool) : Tot Type = squash (test == v) inline_for_extraction let mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t = if test then x1 () else x2 () let mk_if (test ty e_true e_false: T.term) : T.Tac T.term = let bt = T.fresh_binder (T.mk_app (`(ctest true)) [test, T.Q_Explicit]) in let bf = T.fresh_binder (T.mk_app (`(ctest false)) [test, T.Q_Explicit]) in let ft = T.pack (T.Tv_Abs bt e_true) in let ff = T.pack (T.Tv_Abs bf e_false) in T.mk_app (`(mk_if_t)) [ ty, T.Q_Implicit; test, T.Q_Explicit; ft, T.Q_Explicit; ff, T.Q_Explicit; ] let tfail (#a: Type) (s: Prims.string) : T.Tac a = T.debug ("Tactic failure: " ^ s); T.fail s let rec string_of_name (n: T.name) : Tot string = match n with | [] -> "" | [a] -> a | a :: b -> a ^ "." ^ string_of_name b let unfold_fv (t: T.fv) : T.Tac T.term = let env = T.cur_env () in let n = T.inspect_fv t in match T.lookup_typ env n with | Some s -> begin match T.inspect_sigelt s with | T.Sg_Let {isrec=false; lbs=[lb]} -> let nm = string_of_name n in T.debug ("Unfolded definition: " ^ nm); T.(lb.lb_def) | _ -> let nm = string_of_name n in tfail (nm ^ ": not a non-recursive let definition") end | _ -> tfail "Definition not found" let unfold_term (t: T.term) : T.Tac T.term = match T.inspect t with | T.Tv_FVar v -> unfold_fv v | _ -> tfail "Not a global variable" let tsuccess (s: string) : T.Tac unit = T.debug ("Checking success for: " ^ s); T.qed (); T.debug ("Success: " ^ s) let rec to_all_goals (t: unit -> T.Tac unit) : T.Tac unit = if T.ngoals () = 0 then () else let _ = T.divide 1 t (fun () -> to_all_goals t) in () let rec imm_solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit = T.first (List.Tot.append l [ (fun () -> T.trivial (); tsuccess "trivial" ); (fun () -> T.trefl (); tsuccess "reflexivity" ); (fun () -> T.assumption (); tsuccess "assumption" ); (fun () -> T.norm [delta; zeta; iota; primops]; T.trivial (); tsuccess "norm trivial" ); (fun () -> T.apply (`(FStar.Squash.return_squash)); to_all_goals (fun () -> imm_solve_goal l); tsuccess "return_squash imm_solve" ); ]) let tforall_intro () = T.forall_intro () let timplies_intro () = T.implies_intro () let tsplit () = T.split () let rec solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit = if T.ngoals () = 0 then () else begin begin if T.ngoals () > 1 then tfail "More than one goal here" else () end; begin match T.trytac tforall_intro with | Some _ -> T.debug ("Applied: forall_intro"); to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac timplies_intro with | Some _ -> T.debug ("Applied: implies_intro"); to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac tsplit with | Some _ -> let n = T.ngoals () in if n > 2 then tfail "There should be only at most 2 goals here" (* let _ = T.divide 2 (fun () -> to_all_goals solve_goal) (fun () -> to_all_goals T.tadmit) in () *) else to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac (fun () -> imm_solve_goal l) with | Some _ -> () | _ -> if T.debugging () then T.dump "MUST USE SMT FOR THIS ONE"; T.smt (); tsuccess "smt" end end end end end let rec tconclude_with (l: list (unit -> T.Tac unit)) : T.Tac unit = if T.ngoals () > 0 then begin if T.debugging () then T.dump "Some goals left"; let _ = T.divide 1 (fun () -> solve_goal l) (fun () -> tconclude_with l) in () end else T.debug "No goals left" let tconclude () : T.Tac unit = tconclude_with []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "MiniParse.Tac.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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
pol: FStar.Stubs.Tactics.Types.guard_policy -> t: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Tactics.Types.guard_policy", "Prims.unit", "MiniParse.Tac.Base.to_all_goals", "FStar.Tactics.V2.Derived.smt", "FStar.Tactics.V2.Derived.tadmit", "FStar.Tactics.V2.Derived.with_policy" ]
[]
false
true
false
false
false
let according_to (pol: T.guard_policy) (t: (unit -> T.Tac unit)) : T.Tac unit =
match pol with | T.SMT -> to_all_goals T.smt | T.Drop -> to_all_goals T.tadmit | _ -> T.with_policy pol t
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.merge
val merge (#elt a1 a2: _) : i: array elt {i == merge' a1 a2}
val merge (#elt a1 a2: _) : i: array elt {i == merge' a1 a2}
let merge #elt a1 a2 : i:array elt{ i == merge' a1 a2 } = merge' a1 a2
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 14, "end_line": 729, "start_col": 0, "start_line": 727 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i) let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s) ```pulse ghost fn elim_in_bounds (#elt:Type) (#i #j:nat) (s:array elt) (p:in_bounds i j s) requires emp ensures pure (i <= j /\ j <= length s) { () } ``` let token (x:'a) = emp let pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop = exists* (q:in_bounds i j x). pts_to (array_slice x i j) #p s ** token q ```pulse ghost fn pts_to_range_prop' (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ensures pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ Seq.length s == j - i) ) { unfold pts_to_range a i j #p s; with q. assert (token #(in_bounds i j a) q); elim_in_bounds a q; pts_to_len (array_slice a i j); fold pts_to_range a i j #p s; } ``` let pts_to_range_prop = pts_to_range_prop' ```pulse ghost fn pts_to_range_intro' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to a #p s ensures pts_to_range a 0 (length a) #p s { rewrite each a as (array_slice a 0 (length a)); let q : in_bounds 0 (length a) a = (); fold (token #(in_bounds 0 (length a) a) q); fold (pts_to_range a 0 (length a) #p s); } ``` let pts_to_range_intro = pts_to_range_intro' ```pulse ghost fn pts_to_range_elim' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to_range a 0 (length a) #p s ensures pts_to a #p s { unfold (pts_to_range a 0 (length a) #p s); unfold (token #(in_bounds 0 (length a) a) _); rewrite each (array_slice a 0 (length a)) as a; } ``` let pts_to_range_elim = pts_to_range_elim' let mk_carrier_split (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: perm) (i: nat) (_:squash ( offset + Seq.length s <= len /\ i <= Seq.length s )) : squash ( let c1 = mk_carrier len offset (Seq.slice s 0 i) p in let c2 = mk_carrier len (offset + i) (Seq.slice s i (Seq.length s)) p in composable c1 c2 /\ mk_carrier len offset s p `Map.equal` (c1 `compose` c2) ) = () ```pulse ghost fn use_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn ghost_split (#elt: Type) (#x: Seq.seq elt) (#p: perm) (a: array elt) (i: nat {i <= length a}) requires pts_to a #p x returns _: squash (i <= length a /\ i <= Seq.length x) ensures pts_to (split_r a i) #p (Seq.slice x i (Seq.length x)) ** pts_to (split_l a i) #p (Seq.slice x 0 i) ** pure (x `Seq.equal` Seq.append (Seq.slice x 0 i) (Seq.slice x i (Seq.length x))) { unfold (pts_to a #p x); use_squash (mk_carrier_split (SZ.v (ptr_of a).base_len) (ptr_of a).offset x p i ()); let xl = Seq.slice x 0 i; let xr = Seq.slice x i (Seq.length x); let vl = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) xl p; let vr = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset + i) xr p; Pulse.Lib.Core.share (ptr_of a).base vl vr; rewrite pcm_pts_to (ptr_of a).base vl as pcm_pts_to (ptr_of (split_l a i)).base vl; rewrite pcm_pts_to (ptr_of a).base vr as pcm_pts_to (ptr_of (split_r a i)).base vr; fold (pts_to (split_l a i) #p xl); fold (pts_to (split_r a i) #p xr); } ``` let vprop_equiv_refl_eq (v0 v1:vprop) (_:squash (v0 == v1)) : vprop_equiv v0 v1 = vprop_equiv_refl v0 let equiv () : FStar.Tactics.Tac unit = let open FStar.Tactics in mapply (`vprop_equiv_refl_eq); smt() ```pulse ghost fn split_l_slice #elt (a : array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_l (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a i m) #p s { rewrite each (split_l (array_slice a i j) (m - i)) as (array_slice a i m); } ``` ```pulse ghost fn split_r_slice #elt (a:array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_r (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a m j) #p s { rewrite each (split_r (array_slice a i j) (m - i)) as (array_slice a m j); } ``` ```pulse ghost fn pts_to_range_split' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ** pure (i <= m /\ m <= j) ensures exists* s1 s2. pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ** pure ( i <= m /\ m <= j /\ j <= length a /\ eq2 #int (Seq.length s) (j - i) /\ s1 == Seq.slice s 0 (m - i) /\ s2 == Seq.slice s (m - i) (Seq.length s) /\ s == Seq.append s1 s2 ) { pts_to_range_prop a; unfold pts_to_range a i j #p s; unfold (token #(in_bounds i j a) _); ghost_split (array_slice a i j) (m - i); split_r_slice a i m j #(Seq.slice s (m - i) (Seq.length s)) (); split_l_slice a i m j (); let q1 : in_bounds i m a = (); let q2 : in_bounds m j a = (); fold (token #(in_bounds i m a) q1); fold (token #(in_bounds m j a) q2); fold (pts_to_range a i m #p (Seq.slice s 0 (m - i))); fold (pts_to_range a m j #p (Seq.slice s (m - i) (Seq.length s))); assert pure (s `Seq.equal` Seq.append (Seq.slice s 0 (m - i)) (Seq.slice s (m - i) (Seq.length s))); } ``` let pts_to_range_split = pts_to_range_split' let mk_carrier_merge (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p: perm) (_:squash ( offset + Seq.length s1 + Seq.length s2 <= len )) : squash ( let c1 = mk_carrier len offset s1 p in let c2 = mk_carrier len (offset + Seq.length s1) s2 p in composable c1 c2 /\ mk_carrier len offset (s1 `Seq.append` s2) p `Map.equal` (c1 `compose` c2) ) = () let adjacent (#elt: Type) (a1 a2: array elt) : Tot prop = base (ptr_of a1) == base (ptr_of a2) /\ offset (ptr_of a1) + (length a1) == offset (ptr_of a2) let merge' (#elt: Type) (a1: array elt) (a2:array elt { adjacent a1 a2 }) = { p = ptr_of a1; length=Ghost.hide (length a1 + length a2) }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a1: Pulse.Lib.HigherArray.array elt -> a2: Pulse.Lib.HigherArray.array elt {Pulse.Lib.HigherArray.adjacent a1 a2} -> i: Pulse.Lib.HigherArray.array elt {i == Pulse.Lib.HigherArray.merge' a1 a2}
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.array", "Pulse.Lib.HigherArray.adjacent", "Pulse.Lib.HigherArray.merge'", "Prims.eq2" ]
[]
false
false
false
false
false
let merge #elt a1 a2 : i: array elt {i == merge' a1 a2} =
merge' a1 a2
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.pts_to_range_join
val pts_to_range_join (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s1 #s2: Seq.seq elt) : stt_ghost unit (pts_to_range a i m #p s1 ** pts_to_range a m j #p s2) (fun _ -> pts_to_range a i j #p (s1 `Seq.append` s2))
val pts_to_range_join (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s1 #s2: Seq.seq elt) : stt_ghost unit (pts_to_range a i m #p s1 ** pts_to_range a m j #p s2) (fun _ -> pts_to_range a i j #p (s1 `Seq.append` s2))
let pts_to_range_join = pts_to_range_join'
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 800, "start_col": 0, "start_line": 800 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i) let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s) ```pulse ghost fn elim_in_bounds (#elt:Type) (#i #j:nat) (s:array elt) (p:in_bounds i j s) requires emp ensures pure (i <= j /\ j <= length s) { () } ``` let token (x:'a) = emp let pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop = exists* (q:in_bounds i j x). pts_to (array_slice x i j) #p s ** token q ```pulse ghost fn pts_to_range_prop' (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ensures pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ Seq.length s == j - i) ) { unfold pts_to_range a i j #p s; with q. assert (token #(in_bounds i j a) q); elim_in_bounds a q; pts_to_len (array_slice a i j); fold pts_to_range a i j #p s; } ``` let pts_to_range_prop = pts_to_range_prop' ```pulse ghost fn pts_to_range_intro' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to a #p s ensures pts_to_range a 0 (length a) #p s { rewrite each a as (array_slice a 0 (length a)); let q : in_bounds 0 (length a) a = (); fold (token #(in_bounds 0 (length a) a) q); fold (pts_to_range a 0 (length a) #p s); } ``` let pts_to_range_intro = pts_to_range_intro' ```pulse ghost fn pts_to_range_elim' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to_range a 0 (length a) #p s ensures pts_to a #p s { unfold (pts_to_range a 0 (length a) #p s); unfold (token #(in_bounds 0 (length a) a) _); rewrite each (array_slice a 0 (length a)) as a; } ``` let pts_to_range_elim = pts_to_range_elim' let mk_carrier_split (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: perm) (i: nat) (_:squash ( offset + Seq.length s <= len /\ i <= Seq.length s )) : squash ( let c1 = mk_carrier len offset (Seq.slice s 0 i) p in let c2 = mk_carrier len (offset + i) (Seq.slice s i (Seq.length s)) p in composable c1 c2 /\ mk_carrier len offset s p `Map.equal` (c1 `compose` c2) ) = () ```pulse ghost fn use_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn ghost_split (#elt: Type) (#x: Seq.seq elt) (#p: perm) (a: array elt) (i: nat {i <= length a}) requires pts_to a #p x returns _: squash (i <= length a /\ i <= Seq.length x) ensures pts_to (split_r a i) #p (Seq.slice x i (Seq.length x)) ** pts_to (split_l a i) #p (Seq.slice x 0 i) ** pure (x `Seq.equal` Seq.append (Seq.slice x 0 i) (Seq.slice x i (Seq.length x))) { unfold (pts_to a #p x); use_squash (mk_carrier_split (SZ.v (ptr_of a).base_len) (ptr_of a).offset x p i ()); let xl = Seq.slice x 0 i; let xr = Seq.slice x i (Seq.length x); let vl = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) xl p; let vr = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset + i) xr p; Pulse.Lib.Core.share (ptr_of a).base vl vr; rewrite pcm_pts_to (ptr_of a).base vl as pcm_pts_to (ptr_of (split_l a i)).base vl; rewrite pcm_pts_to (ptr_of a).base vr as pcm_pts_to (ptr_of (split_r a i)).base vr; fold (pts_to (split_l a i) #p xl); fold (pts_to (split_r a i) #p xr); } ``` let vprop_equiv_refl_eq (v0 v1:vprop) (_:squash (v0 == v1)) : vprop_equiv v0 v1 = vprop_equiv_refl v0 let equiv () : FStar.Tactics.Tac unit = let open FStar.Tactics in mapply (`vprop_equiv_refl_eq); smt() ```pulse ghost fn split_l_slice #elt (a : array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_l (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a i m) #p s { rewrite each (split_l (array_slice a i j) (m - i)) as (array_slice a i m); } ``` ```pulse ghost fn split_r_slice #elt (a:array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_r (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a m j) #p s { rewrite each (split_r (array_slice a i j) (m - i)) as (array_slice a m j); } ``` ```pulse ghost fn pts_to_range_split' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ** pure (i <= m /\ m <= j) ensures exists* s1 s2. pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ** pure ( i <= m /\ m <= j /\ j <= length a /\ eq2 #int (Seq.length s) (j - i) /\ s1 == Seq.slice s 0 (m - i) /\ s2 == Seq.slice s (m - i) (Seq.length s) /\ s == Seq.append s1 s2 ) { pts_to_range_prop a; unfold pts_to_range a i j #p s; unfold (token #(in_bounds i j a) _); ghost_split (array_slice a i j) (m - i); split_r_slice a i m j #(Seq.slice s (m - i) (Seq.length s)) (); split_l_slice a i m j (); let q1 : in_bounds i m a = (); let q2 : in_bounds m j a = (); fold (token #(in_bounds i m a) q1); fold (token #(in_bounds m j a) q2); fold (pts_to_range a i m #p (Seq.slice s 0 (m - i))); fold (pts_to_range a m j #p (Seq.slice s (m - i) (Seq.length s))); assert pure (s `Seq.equal` Seq.append (Seq.slice s 0 (m - i)) (Seq.slice s (m - i) (Seq.length s))); } ``` let pts_to_range_split = pts_to_range_split' let mk_carrier_merge (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p: perm) (_:squash ( offset + Seq.length s1 + Seq.length s2 <= len )) : squash ( let c1 = mk_carrier len offset s1 p in let c2 = mk_carrier len (offset + Seq.length s1) s2 p in composable c1 c2 /\ mk_carrier len offset (s1 `Seq.append` s2) p `Map.equal` (c1 `compose` c2) ) = () let adjacent (#elt: Type) (a1 a2: array elt) : Tot prop = base (ptr_of a1) == base (ptr_of a2) /\ offset (ptr_of a1) + (length a1) == offset (ptr_of a2) let merge' (#elt: Type) (a1: array elt) (a2:array elt { adjacent a1 a2 }) = { p = ptr_of a1; length=Ghost.hide (length a1 + length a2) } irreducible let merge #elt a1 a2 : i:array elt{ i == merge' a1 a2 } = merge' a1 a2 ```pulse ghost fn ghost_join (#elt: Type) (#x1 #x2: Seq.seq elt) (#p: perm) (a1 a2: array elt) (h: squash (adjacent a1 a2)) requires pts_to a1 #p x1 ** pts_to a2 #p x2 ensures pts_to (merge a1 a2) #p (x1 `Seq.append` x2) { unfold pts_to a1 #p x1; unfold pts_to a2 #p x2; use_squash (mk_carrier_merge (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 x2 p ()); with w. rewrite pcm_pts_to (ptr_of a2).base w as pcm_pts_to (ptr_of a1).base (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 p); Pulse.Lib.Core.gather (ptr_of a1).base (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 (p)) (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 (p)); with w. rewrite pcm_pts_to (ptr_of a1).base w as pcm_pts_to (ptr_of (merge a1 a2)).base (mk_carrier (SZ.v (ptr_of (merge a1 a2)).base_len) ((ptr_of (merge a1 a2)).offset) (x1 `Seq.append` x2) (p)); fold (pts_to (merge a1 a2) #p (Seq.append x1 x2)); } ``` ```pulse ghost fn pts_to_range_intro_ij (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) (i j: nat) (_:squash (i <= j /\ j <= length a)) requires pts_to (array_slice a i j) #p s ensures pts_to_range a i j #p s { let q : in_bounds i j a = (); fold (token #(in_bounds i j a) q); fold (pts_to_range a i j #p s); } ``` ```pulse ghost fn pts_to_range_join' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s1 #s2: Seq.seq elt) requires pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ensures pts_to_range a i j #p (s1 `Seq.append` s2) { pts_to_range_prop a #i #m; pts_to_range_prop a #m #j; unfold pts_to_range a i m #p s1; unfold pts_to_range a m j #p s2; ghost_join (array_slice a i m) (array_slice a m j) (); rewrite each (merge (array_slice a i m) (array_slice a m j)) as (array_slice a i j); pts_to_range_intro_ij a _ _ i j (); unfold (token #(in_bounds i m a) _); unfold (token #(in_bounds m j a) _); }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array elt -> i: Prims.nat -> m: Prims.nat -> j: Prims.nat -> Pulse.Lib.Core.stt_ghost Prims.unit (Pulse.Lib.HigherArray.pts_to_range a i m s1 ** Pulse.Lib.HigherArray.pts_to_range a m j s2) (fun _ -> Pulse.Lib.HigherArray.pts_to_range a i j (FStar.Seq.Base.append s1 s2))
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.pts_to_range_join'" ]
[]
false
false
false
false
false
let pts_to_range_join =
pts_to_range_join'
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.null_ptr
val null_ptr (a: Type u#a) : ptr a
val null_ptr (a: Type u#a) : ptr a
let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 }
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 67, "end_line": 55, "start_col": 0, "start_line": 53 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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 -> Pulse.Lib.HigherArray.ptr a
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.Mkptr", "FStar.Ghost.hide", "FStar.SizeT.t", "FStar.SizeT.__uint_to_t", "Pulse.Lib.Core.pcm_ref_null", "Pulse.Lib.PCM.Array.carrier", "Prims.nat", "Pulse.Lib.PCM.Array.pcm", "Pulse.Lib.HigherArray.ptr" ]
[]
false
false
false
true
false
let null_ptr (a: Type u#a) : ptr a =
{ base_len = 0sz; base = pcm_ref_null (PA.pcm a 0); offset = 0 }
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.offset
val offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p)))
val offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p)))
let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 10, "end_line": 69, "start_col": 0, "start_line": 67 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |)
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Pulse.Lib.HigherArray.ptr elt -> Prims.Ghost Prims.nat
Prims.Ghost
[]
[]
[ "Pulse.Lib.HigherArray.ptr", "Pulse.Lib.HigherArray.__proj__Mkptr__item__offset", "Prims.nat", "Prims.l_True", "Prims.b2t", "Prims.op_LessThanOrEqual", "Pulse.Lib.HigherArray.base_len", "Pulse.Lib.HigherArray.base" ]
[]
false
false
false
false
false
let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) =
p.offset
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.null
val null (#a: Type u#1) : array a
val null (#a: Type u#1) : array a
let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 }
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 106, "start_col": 0, "start_line": 105 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a))
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Pulse.Lib.HigherArray.array a
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.Mkarray", "Pulse.Lib.HigherArray.null_ptr", "FStar.Ghost.hide", "Prims.nat", "Pulse.Lib.HigherArray.array" ]
[]
false
false
false
true
false
let null (#a: Type u#1) : array a =
{ p = null_ptr a; length = Ghost.hide 0 }
false
MiniParse.Tac.Base.fst
MiniParse.Tac.Base.mk_if_t
val mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t
val mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t
let mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t = if test then x1 () else x2 ()
{ "file_name": "examples/miniparse/MiniParse.Tac.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 47, "start_col": 0, "start_line": 46 }
(* 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 MiniParse.Tac.Base module T = FStar.Tactics.V2 module L = FStar.List.Tot let pack_nat (n: nat) : T.Tac T.term = T.pack (T.Tv_Const (T.C_Int n)) let rec app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv) = let ins = T.inspect t in if T.Tv_App? ins then let (T.Tv_App u v) = ins in let (x, l) = app_head_rev_tail u in (x, v :: l) else (t, []) let app_head_tail (t: T.term) : T.Tac (T.term * list T.argv) = let (x, l) = app_head_rev_tail t in (x, L.rev l) inline_for_extraction let ctest (v: bool) (test: bool) : Tot Type = squash (test == v)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "MiniParse.Tac.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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
test: Prims.bool -> x1: (_: MiniParse.Tac.Base.ctest true test -> t) -> x2: (_: MiniParse.Tac.Base.ctest false test -> t) -> t
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "MiniParse.Tac.Base.ctest" ]
[]
false
false
false
false
false
let mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t =
if test then x1 () else x2 ()
false
Steel.ST.Reference.fst
Steel.ST.Reference.ref
val ref ([@@@ unused] a:Type0) : Type0
val ref ([@@@ unused] a:Type0) : Type0
let ref (a:Type0) : Type0 = R.ref a
{ "file_name": "lib/steel/Steel.ST.Reference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 11, "end_line": 25, "start_col": 0, "start_line": 23 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Reference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Reference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "Steel.Reference.ref" ]
[]
false
false
false
true
true
let ref (a: Type0) : Type0 =
R.ref a
false
MiniParse.Tac.Base.fst
MiniParse.Tac.Base.solve_goal
val solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit
val solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit
let rec solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit = if T.ngoals () = 0 then () else begin begin if T.ngoals () > 1 then tfail "More than one goal here" else () end; begin match T.trytac tforall_intro with | Some _ -> T.debug ("Applied: forall_intro"); to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac timplies_intro with | Some _ -> T.debug ("Applied: implies_intro"); to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac tsplit with | Some _ -> let n = T.ngoals () in if n > 2 then tfail "There should be only at most 2 goals here" (* let _ = T.divide 2 (fun () -> to_all_goals solve_goal) (fun () -> to_all_goals T.tadmit) in () *) else to_all_goals (fun () -> solve_goal l) | _ -> begin match T.trytac (fun () -> imm_solve_goal l) with | Some _ -> () | _ -> if T.debugging () then T.dump "MUST USE SMT FOR THIS ONE"; T.smt (); tsuccess "smt" end end end end end
{ "file_name": "examples/miniparse/MiniParse.Tac.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 180, "start_col": 0, "start_line": 136 }
(* 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 MiniParse.Tac.Base module T = FStar.Tactics.V2 module L = FStar.List.Tot let pack_nat (n: nat) : T.Tac T.term = T.pack (T.Tv_Const (T.C_Int n)) let rec app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv) = let ins = T.inspect t in if T.Tv_App? ins then let (T.Tv_App u v) = ins in let (x, l) = app_head_rev_tail u in (x, v :: l) else (t, []) let app_head_tail (t: T.term) : T.Tac (T.term * list T.argv) = let (x, l) = app_head_rev_tail t in (x, L.rev l) inline_for_extraction let ctest (v: bool) (test: bool) : Tot Type = squash (test == v) inline_for_extraction let mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t = if test then x1 () else x2 () let mk_if (test ty e_true e_false: T.term) : T.Tac T.term = let bt = T.fresh_binder (T.mk_app (`(ctest true)) [test, T.Q_Explicit]) in let bf = T.fresh_binder (T.mk_app (`(ctest false)) [test, T.Q_Explicit]) in let ft = T.pack (T.Tv_Abs bt e_true) in let ff = T.pack (T.Tv_Abs bf e_false) in T.mk_app (`(mk_if_t)) [ ty, T.Q_Implicit; test, T.Q_Explicit; ft, T.Q_Explicit; ff, T.Q_Explicit; ] let tfail (#a: Type) (s: Prims.string) : T.Tac a = T.debug ("Tactic failure: " ^ s); T.fail s let rec string_of_name (n: T.name) : Tot string = match n with | [] -> "" | [a] -> a | a :: b -> a ^ "." ^ string_of_name b let unfold_fv (t: T.fv) : T.Tac T.term = let env = T.cur_env () in let n = T.inspect_fv t in match T.lookup_typ env n with | Some s -> begin match T.inspect_sigelt s with | T.Sg_Let {isrec=false; lbs=[lb]} -> let nm = string_of_name n in T.debug ("Unfolded definition: " ^ nm); T.(lb.lb_def) | _ -> let nm = string_of_name n in tfail (nm ^ ": not a non-recursive let definition") end | _ -> tfail "Definition not found" let unfold_term (t: T.term) : T.Tac T.term = match T.inspect t with | T.Tv_FVar v -> unfold_fv v | _ -> tfail "Not a global variable" let tsuccess (s: string) : T.Tac unit = T.debug ("Checking success for: " ^ s); T.qed (); T.debug ("Success: " ^ s) let rec to_all_goals (t: unit -> T.Tac unit) : T.Tac unit = if T.ngoals () = 0 then () else let _ = T.divide 1 t (fun () -> to_all_goals t) in () let rec imm_solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit = T.first (List.Tot.append l [ (fun () -> T.trivial (); tsuccess "trivial" ); (fun () -> T.trefl (); tsuccess "reflexivity" ); (fun () -> T.assumption (); tsuccess "assumption" ); (fun () -> T.norm [delta; zeta; iota; primops]; T.trivial (); tsuccess "norm trivial" ); (fun () -> T.apply (`(FStar.Squash.return_squash)); to_all_goals (fun () -> imm_solve_goal l); tsuccess "return_squash imm_solve" ); ]) let tforall_intro () = T.forall_intro () let timplies_intro () = T.implies_intro () let tsplit () = T.split ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "MiniParse.Tac.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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
l: Prims.list (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "Prims.unit", "Prims.bool", "FStar.Tactics.NamedView.binding", "MiniParse.Tac.Base.to_all_goals", "MiniParse.Tac.Base.solve_goal", "FStar.Tactics.V2.Derived.debug", "FStar.Pervasives.Native.option", "Prims.op_GreaterThan", "MiniParse.Tac.Base.tfail", "Prims.int", "FStar.Tactics.V2.Derived.ngoals", "MiniParse.Tac.Base.tsuccess", "FStar.Tactics.V2.Derived.smt", "FStar.Stubs.Tactics.V2.Builtins.dump", "FStar.Stubs.Tactics.V2.Builtins.debugging", "FStar.Tactics.V2.Derived.trytac", "MiniParse.Tac.Base.imm_solve_goal", "MiniParse.Tac.Base.tsplit", "MiniParse.Tac.Base.timplies_intro", "MiniParse.Tac.Base.tforall_intro", "Prims.op_Equality" ]
[ "recursion" ]
false
true
false
false
false
let rec solve_goal (l: list (unit -> T.Tac unit)) : T.Tac unit =
if T.ngoals () = 0 then () else (if T.ngoals () > 1 then tfail "More than one goal here"; match T.trytac tforall_intro with | Some _ -> T.debug ("Applied: forall_intro"); to_all_goals (fun () -> solve_goal l) | _ -> match T.trytac timplies_intro with | Some _ -> T.debug ("Applied: implies_intro"); to_all_goals (fun () -> solve_goal l) | _ -> match T.trytac tsplit with | Some _ -> let n = T.ngoals () in if n > 2 then tfail "There should be only at most 2 goals here" else to_all_goals (fun () -> solve_goal l) | _ -> match T.trytac (fun () -> imm_solve_goal l) with | Some _ -> () | _ -> if T.debugging () then T.dump "MUST USE SMT FOR THIS ONE"; T.smt (); tsuccess "smt")
false
Steel.ST.Reference.fst
Steel.ST.Reference.pts_to
val pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop
val pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop
let pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop = R.pts_to r p v
{ "file_name": "lib/steel/Steel.ST.Reference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 18, "end_line": 40, "start_col": 0, "start_line": 35 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Reference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference let ref (a:Type0) : Type0 = R.ref a let null (#a:Type0) : ref a = R.null #a let is_null (#a:Type0) (r:ref a) : b:bool{b <==> r == null} = R.is_null r
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Reference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.ST.Reference.ref a -> p: Steel.FractionalPermission.perm -> v: a -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.Reference.ref", "Steel.FractionalPermission.perm", "Steel.Reference.pts_to", "Steel.Effect.Common.vprop" ]
[]
false
false
false
true
false
let pts_to (#a: Type0) (r: ref a) ([@@@ smt_fallback]p: perm) ([@@@ smt_fallback]v: a) : vprop =
R.pts_to r p v
false
Steel.ST.Reference.fst
Steel.ST.Reference.null
val null (#a:Type0) : ref a
val null (#a:Type0) : ref a
let null (#a:Type0) : ref a = R.null #a
{ "file_name": "lib/steel/Steel.ST.Reference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 29, "start_col": 0, "start_line": 27 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Reference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference let ref (a:Type0) : Type0 = R.ref a
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Reference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Steel.ST.Reference.ref a
Prims.Tot
[ "total" ]
[]
[ "Steel.Reference.null", "Steel.ST.Reference.ref" ]
[]
false
false
false
true
false
let null (#a: Type0) : ref a =
R.null #a
false
MiniParse.Tac.Base.fst
MiniParse.Tac.Base.app_head_rev_tail
val app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv)
val app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv)
let rec app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv) = let ins = T.inspect t in if T.Tv_App? ins then let (T.Tv_App u v) = ins in let (x, l) = app_head_rev_tail u in (x, v :: l) else (t, [])
{ "file_name": "examples/miniparse/MiniParse.Tac.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 34, "start_col": 0, "start_line": 24 }
(* 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 MiniParse.Tac.Base module T = FStar.Tactics.V2 module L = FStar.List.Tot let pack_nat (n: nat) : T.Tac T.term = T.pack (T.Tv_Const (T.C_Int n))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "MiniParse.Tac.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.term * Prims.list FStar.Stubs.Reflection.V2.Data.argv)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.uu___is_Tv_App", "FStar.Stubs.Reflection.V2.Data.argv", "Prims.list", "FStar.Pervasives.Native.Mktuple2", "Prims.Cons", "FStar.Pervasives.Native.tuple2", "MiniParse.Tac.Base.app_head_rev_tail", "FStar.Tactics.NamedView.named_term_view", "Prims.bool", "Prims.Nil", "FStar.Tactics.NamedView.inspect" ]
[ "recursion" ]
false
true
false
false
false
let rec app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv) =
let ins = T.inspect t in if T.Tv_App? ins then let T.Tv_App u v = ins in let x, l = app_head_rev_tail u in (x, v :: l) else (t, [])
false
MiniParse.Tac.Base.fst
MiniParse.Tac.Base.string_of_name
val string_of_name (n: T.name) : Tot string
val string_of_name (n: T.name) : Tot string
let rec string_of_name (n: T.name) : Tot string = match n with | [] -> "" | [a] -> a | a :: b -> a ^ "." ^ string_of_name b
{ "file_name": "examples/miniparse/MiniParse.Tac.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 69, "start_col": 0, "start_line": 65 }
(* 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 MiniParse.Tac.Base module T = FStar.Tactics.V2 module L = FStar.List.Tot let pack_nat (n: nat) : T.Tac T.term = T.pack (T.Tv_Const (T.C_Int n)) let rec app_head_rev_tail (t: T.term) : T.Tac (T.term * list T.argv) = let ins = T.inspect t in if T.Tv_App? ins then let (T.Tv_App u v) = ins in let (x, l) = app_head_rev_tail u in (x, v :: l) else (t, []) let app_head_tail (t: T.term) : T.Tac (T.term * list T.argv) = let (x, l) = app_head_rev_tail t in (x, L.rev l) inline_for_extraction let ctest (v: bool) (test: bool) : Tot Type = squash (test == v) inline_for_extraction let mk_if_t (#t: Type) (test: bool) (x1: (ctest true test -> Tot t)) (x2: (ctest false test -> Tot t)) : Tot t = if test then x1 () else x2 () let mk_if (test ty e_true e_false: T.term) : T.Tac T.term = let bt = T.fresh_binder (T.mk_app (`(ctest true)) [test, T.Q_Explicit]) in let bf = T.fresh_binder (T.mk_app (`(ctest false)) [test, T.Q_Explicit]) in let ft = T.pack (T.Tv_Abs bt e_true) in let ff = T.pack (T.Tv_Abs bf e_false) in T.mk_app (`(mk_if_t)) [ ty, T.Q_Implicit; test, T.Q_Explicit; ft, T.Q_Explicit; ff, T.Q_Explicit; ] let tfail (#a: Type) (s: Prims.string) : T.Tac a = T.debug ("Tactic failure: " ^ s); T.fail s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "MiniParse.Tac.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Tac", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: FStar.Stubs.Reflection.Types.name -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "FStar.Stubs.Reflection.Types.name", "Prims.string", "Prims.list", "Prims.op_Hat", "MiniParse.Tac.Base.string_of_name" ]
[ "recursion" ]
false
false
false
true
false
let rec string_of_name (n: T.name) : Tot string =
match n with | [] -> "" | [a] -> a | a :: b -> a ^ "." ^ string_of_name b
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.op_Array_Assignment
val op_Array_Assignment (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) : stt unit (requires pts_to a s) (ensures fun res -> pts_to a (Seq.upd s (SZ.v i) v))
val op_Array_Assignment (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) : stt unit (requires pts_to a s) (ensures fun res -> pts_to a (Seq.upd s (SZ.v i) v))
let op_Array_Assignment = write
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 31, "end_line": 264, "start_col": 0, "start_line": 264 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array t -> i: FStar.SizeT.t -> v: t -> Pulse.Lib.Core.stt Prims.unit (Pulse.Lib.HigherArray.pts_to a (FStar.Ghost.reveal s)) (fun _ -> Pulse.Lib.HigherArray.pts_to a (FStar.Seq.Base.upd (FStar.Ghost.reveal s) (FStar.SizeT.v i) v))
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.write" ]
[]
false
false
false
false
false
let op_Array_Assignment =
write
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.mk_array
val mk_array (#elt: Type u#1) (base_len: SZ.t) (base: l_pcm_ref elt base_len) (offset: nat{offset <= SZ.v base_len}) : array elt
val mk_array (#elt: Type u#1) (base_len: SZ.t) (base: l_pcm_ref elt base_len) (offset: nat{offset <= SZ.v base_len}) : array elt
let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) }
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 82, "end_line": 133, "start_col": 0, "start_line": 127 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a )
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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
base_len: FStar.SizeT.t -> base: Pulse.Lib.HigherArray.l_pcm_ref elt base_len -> offset: Prims.nat{offset <= FStar.SizeT.v base_len} -> Pulse.Lib.HigherArray.array elt
Prims.Tot
[ "total" ]
[]
[ "FStar.SizeT.t", "Pulse.Lib.HigherArray.l_pcm_ref", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.SizeT.v", "Pulse.Lib.HigherArray.Mkarray", "Pulse.Lib.HigherArray.Mkptr", "FStar.Ghost.hide", "Prims.op_Subtraction", "Pulse.Lib.HigherArray.array" ]
[]
false
false
false
false
false
let mk_array (#elt: Type u#1) (base_len: SZ.t) (base: l_pcm_ref elt base_len) (offset: nat{offset <= SZ.v base_len}) : array elt =
{ p = { base_len = base_len; base = base; offset = offset }; length = Ghost.hide (SZ.v base_len - offset) }
false
Steel.ST.Reference.fst
Steel.ST.Reference._stack_frame
val _stack_frame:vprop
val _stack_frame:vprop
let _stack_frame : vprop = pure True
{ "file_name": "lib/steel/Steel.ST.Reference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 36, "end_line": 107, "start_col": 0, "start_line": 107 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Reference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference let ref (a:Type0) : Type0 = R.ref a let null (#a:Type0) : ref a = R.null #a let is_null (#a:Type0) (r:ref a) : b:bool{b <==> r == null} = R.is_null r let pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop = R.pts_to r p v let pts_to_injective_eq (#a: Type) (#opened:inames) (#p0 #p1:perm) (#v0 #v1:a) (r: ref a) : STGhost unit opened (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.pts_to_injective_eq #a #opened #p0 #p1 #(hide v0) #(hide v1) r) let pts_to_not_null #a #opened #p #v r = extract_fact #opened (pts_to r p v) (r =!= null) (R.pts_to_not_null r p v); () let pts_to_perm r = coerce_ghost (fun _ -> R.pts_to_perm r) let alloc (#a:Type) (x:a) : ST (ref a) emp (fun r -> pts_to r full_perm x) (requires True) (ensures fun r -> not (is_null r)) = let r = coerce_steel (fun _ -> R.alloc_pt x) in r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) : ST a (pts_to r p v) (fun _ -> pts_to r p v) (requires True) (ensures fun x -> x == Ghost.reveal v) = let u = coerce_steel (fun _ -> R.read_pt r) in return u let write (#a:Type0) (#v:erased a) (r:ref a) (x:a) : STT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = coerce_steel (fun _ -> R.write_pt r x); return () let free (#a:Type0) (#v:erased a) (r:ref a) : STT unit (pts_to r full_perm v) (fun _ -> emp) = coerce_steel(fun _ -> R.free_pt r); return () /// Local primitive, to be extracted to Low* EPushFrame. To remember /// that we need to call some pop_frame later, we insert some dummy
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Reference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.Util.pure", "Prims.l_True" ]
[]
false
false
false
true
false
let _stack_frame:vprop =
pure True
false
Steel.ST.C.Types.Fields.fsti
Steel.ST.C.Types.Fields.norm_fields
val norm_fields: Prims.unit -> FStar.Tactics.Tac unit
val norm_fields: Prims.unit -> FStar.Tactics.Tac unit
let norm_fields () : FStar.Tactics.Tac unit = FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops]; FStar.Tactics.trefl ()
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Fields.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 24, "end_line": 9, "start_col": 0, "start_line": 7 }
module Steel.ST.C.Types.Fields include Steel.ST.C.Types.Base open Steel.C.Typestring open Steel.ST.Util
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.C.Types.Base.fsti.checked", "Steel.C.Typestring.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Fields.fsti" }
[ { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.C.Typestring", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.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
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.trefl", "FStar.Stubs.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_attr", "Prims.string", "Prims.Nil", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "FStar.Pervasives.primops" ]
[]
false
true
false
false
false
let norm_fields () : FStar.Tactics.Tac unit =
FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops]; FStar.Tactics.trefl ()
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.ptr_shift
val ptr_shift (#elt: Type) (p: ptr elt) (off: nat{offset p + off <= base_len (base p)}) : ptr elt
val ptr_shift (#elt: Type) (p: ptr elt) (off: nat{offset p + off <= base_len (base p)}) : ptr elt
let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; }
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 444, "start_col": 0, "start_line": 435 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather'
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Pulse.Lib.HigherArray.ptr elt -> off: Prims.nat { Pulse.Lib.HigherArray.offset p + off <= Pulse.Lib.HigherArray.base_len (Pulse.Lib.HigherArray.base p) } -> Pulse.Lib.HigherArray.ptr elt
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.ptr", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Pulse.Lib.HigherArray.offset", "Pulse.Lib.HigherArray.base_len", "Pulse.Lib.HigherArray.base", "Pulse.Lib.HigherArray.Mkptr", "Pulse.Lib.HigherArray.__proj__Mkptr__item__base_len", "Pulse.Lib.HigherArray.__proj__Mkptr__item__base", "Pulse.Lib.HigherArray.__proj__Mkptr__item__offset" ]
[]
false
false
false
false
false
let ptr_shift (#elt: Type) (p: ptr elt) (off: nat{offset p + off <= base_len (base p)}) : ptr elt =
{ base_len = p.base_len; base = p.base; offset = p.offset + off }
false
Steel.ST.C.Types.Fields.fsti
Steel.ST.C.Types.Fields.nonempty_field_description_t
val nonempty_field_description_t : t: Type0 -> Type
let nonempty_field_description_t (t: Type0) = (fd: field_description_t t { fd.fd_empty == false })
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Fields.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 54, "end_line": 27, "start_col": 0, "start_line": 26 }
module Steel.ST.C.Types.Fields include Steel.ST.C.Types.Base open Steel.C.Typestring open Steel.ST.Util [@@noextract_to "krml"] // tactic let norm_fields () : FStar.Tactics.Tac unit = FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops]; FStar.Tactics.trefl () [@@noextract_to "krml"] // primitive val field_t_nil: Type0 [@@noextract_to "krml"] // primitive val field_t_cons (fn: Type0) (ft: Type0) (fc: Type0): Type0 inline_for_extraction [@@noextract_to "krml"; norm_field_attr] noeq type field_description_t (t: Type0) : Type u#1 = { fd_def: (string -> GTot bool); fd_empty: (fd_empty: bool { fd_empty == true <==> (forall s . fd_def s == false) }); fd_type: (string -> Type0); fd_typedef: ((s: string) -> Pure (typedef (fd_type s)) (requires (fd_def s)) (ensures (fun _ -> True))); }
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.C.Types.Base.fsti.checked", "Steel.C.Typestring.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Fields.fsti" }
[ { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.C.Typestring", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.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
t: Type0 -> Type
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.C.Types.Fields.field_description_t", "Prims.eq2", "Prims.bool", "Steel.ST.C.Types.Fields.__proj__Mkfield_description_t__item__fd_empty" ]
[]
false
false
false
true
true
let nonempty_field_description_t (t: Type0) =
(fd: field_description_t t {fd.fd_empty == false})
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.pts_to_range
val pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop
val pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop
let pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop = exists* (q:in_bounds i j x). pts_to (array_slice x i j) #p s ** token q
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 73, "end_line": 504, "start_col": 0, "start_line": 496 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i) let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s) ```pulse ghost fn elim_in_bounds (#elt:Type) (#i #j:nat) (s:array elt) (p:in_bounds i j s) requires emp ensures pure (i <= j /\ j <= length s) { () } ``` let token (x:'a) = emp
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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: Pulse.Lib.HigherArray.array a -> i: Prims.nat -> j: Prims.nat -> s: FStar.Seq.Base.seq a -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.array", "Prims.nat", "PulseCore.FractionalPermission.perm", "FStar.Seq.Base.seq", "Pulse.Lib.Core.op_exists_Star", "Pulse.Lib.HigherArray.in_bounds", "Pulse.Lib.Core.op_Star_Star", "Pulse.Lib.HigherArray.pts_to", "Pulse.Lib.HigherArray.array_slice", "Pulse.Lib.HigherArray.token", "Pulse.Lib.Core.vprop" ]
[]
false
false
false
true
false
let pts_to_range (#a: Type) (x: array a) ([@@@ equate_by_smt]i [@@@ equate_by_smt]j: nat) (#[exact (`full_perm)] p: perm) ([@@@ equate_by_smt]s: Seq.seq a) : vprop =
exists* (q: in_bounds i j x). pts_to (array_slice x i j) #p s ** token q
false
Steel.ST.C.Types.Fields.fsti
Steel.ST.C.Types.Fields.field_description_nil
val field_description_nil:field_description_t field_t_nil
val field_description_nil:field_description_t field_t_nil
let field_description_nil : field_description_t field_t_nil = { fd_def = (fun _ -> false); fd_empty = true; fd_type = (fun _ -> unit); fd_typedef = (fun _ -> false_elim ()); }
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Fields.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 1, "end_line": 38, "start_col": 0, "start_line": 33 }
module Steel.ST.C.Types.Fields include Steel.ST.C.Types.Base open Steel.C.Typestring open Steel.ST.Util [@@noextract_to "krml"] // tactic let norm_fields () : FStar.Tactics.Tac unit = FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops]; FStar.Tactics.trefl () [@@noextract_to "krml"] // primitive val field_t_nil: Type0 [@@noextract_to "krml"] // primitive val field_t_cons (fn: Type0) (ft: Type0) (fc: Type0): Type0 inline_for_extraction [@@noextract_to "krml"; norm_field_attr] noeq type field_description_t (t: Type0) : Type u#1 = { fd_def: (string -> GTot bool); fd_empty: (fd_empty: bool { fd_empty == true <==> (forall s . fd_def s == false) }); fd_type: (string -> Type0); fd_typedef: ((s: string) -> Pure (typedef (fd_type s)) (requires (fd_def s)) (ensures (fun _ -> True))); } inline_for_extraction [@@noextract_to "krml"; norm_field_attr] let nonempty_field_description_t (t: Type0) = (fd: field_description_t t { fd.fd_empty == false }) [@@noextract_to "krml"] // proof-only let field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype = (s: string { fd.fd_def s })
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.C.Types.Base.fsti.checked", "Steel.C.Typestring.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Fields.fsti" }
[ { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.C.Typestring", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.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
Steel.ST.C.Types.Fields.field_description_t Steel.ST.C.Types.Fields.field_t_nil
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.C.Types.Fields.Mkfield_description_t", "Steel.ST.C.Types.Fields.field_t_nil", "Prims.string", "Prims.bool", "Prims.unit", "FStar.Pervasives.false_elim", "Steel.ST.C.Types.Base.typedef" ]
[]
false
false
false
true
false
let field_description_nil:field_description_t field_t_nil =
{ fd_def = (fun _ -> false); fd_empty = true; fd_type = (fun _ -> unit); fd_typedef = (fun _ -> false_elim ()) }
false
Steel.ST.C.Types.Fields.fsti
Steel.ST.C.Types.Fields.field_description_cons
val field_description_cons (#ft #fc: Type0) (n: string) (#fn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == fn))) (t: typedef ft) (fd: field_description_t fc) : Tot (nonempty_field_description_t (field_t_cons fn ft fc))
val field_description_cons (#ft #fc: Type0) (n: string) (#fn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == fn))) (t: typedef ft) (fd: field_description_t fc) : Tot (nonempty_field_description_t (field_t_cons fn ft fc))
let field_description_cons (#ft: Type0) (#fc: Type0) (n: string) (#fn: Type0) (# [ solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == fn))) (t: typedef ft) (fd: field_description_t fc) : Tot (nonempty_field_description_t (field_t_cons fn ft fc)) = field_description_cons0 fn #ft #fc n t fd
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Fields.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 53, "start_col": 0, "start_line": 52 }
module Steel.ST.C.Types.Fields include Steel.ST.C.Types.Base open Steel.C.Typestring open Steel.ST.Util [@@noextract_to "krml"] // tactic let norm_fields () : FStar.Tactics.Tac unit = FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops]; FStar.Tactics.trefl () [@@noextract_to "krml"] // primitive val field_t_nil: Type0 [@@noextract_to "krml"] // primitive val field_t_cons (fn: Type0) (ft: Type0) (fc: Type0): Type0 inline_for_extraction [@@noextract_to "krml"; norm_field_attr] noeq type field_description_t (t: Type0) : Type u#1 = { fd_def: (string -> GTot bool); fd_empty: (fd_empty: bool { fd_empty == true <==> (forall s . fd_def s == false) }); fd_type: (string -> Type0); fd_typedef: ((s: string) -> Pure (typedef (fd_type s)) (requires (fd_def s)) (ensures (fun _ -> True))); } inline_for_extraction [@@noextract_to "krml"; norm_field_attr] let nonempty_field_description_t (t: Type0) = (fd: field_description_t t { fd.fd_empty == false }) [@@noextract_to "krml"] // proof-only let field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype = (s: string { fd.fd_def s }) inline_for_extraction [@@noextract_to "krml"] let field_description_nil : field_description_t field_t_nil = { fd_def = (fun _ -> false); fd_empty = true; fd_type = (fun _ -> unit); fd_typedef = (fun _ -> false_elim ()); } inline_for_extraction [@@noextract_to "krml"; norm_field_attr] let field_description_cons0 (fn: Type0) (#ft: Type0) (#fc: Type0) (n: string) (t: typedef ft) (fd: field_description_t fc) : Tot (nonempty_field_description_t (field_t_cons fn ft fc)) = { fd_def = (fun n' -> n = n' || fd.fd_def n'); fd_empty = false; fd_type = (fun n' -> if n = n' then ft else fd.fd_type n'); fd_typedef = (fun n' -> if n = n' then t else fd.fd_typedef n'); }
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.C.Types.Base.fsti.checked", "Steel.C.Typestring.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Fields.fsti" }
[ { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.C.Typestring", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.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
n: Prims.string -> t: Steel.ST.C.Types.Base.typedef ft -> fd: Steel.ST.C.Types.Fields.field_description_t fc -> Steel.ST.C.Types.Fields.nonempty_field_description_t (Steel.ST.C.Types.Fields.field_t_cons fn ft fc)
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.squash", "FStar.Pervasives.norm", "Steel.C.Typestring.norm_typestring", "Prims.eq2", "Steel.C.Typestring.mk_string_t", "Steel.ST.C.Types.Base.typedef", "Steel.ST.C.Types.Fields.field_description_t", "Steel.ST.C.Types.Fields.field_description_cons0", "Steel.ST.C.Types.Fields.nonempty_field_description_t", "Steel.ST.C.Types.Fields.field_t_cons" ]
[]
false
false
false
false
false
let field_description_cons (#ft #fc: Type0) (n: string) (#fn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == fn))) (t: typedef ft) (fd: field_description_t fc) : Tot (nonempty_field_description_t (field_t_cons fn ft fc)) =
field_description_cons0 fn #ft #fc n t fd
false
Steel.ST.C.Types.Fields.fsti
Steel.ST.C.Types.Fields.field_t
val field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype
val field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype
let field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype = (s: string { fd.fd_def s })
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Fields.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 94, "end_line": 30, "start_col": 0, "start_line": 30 }
module Steel.ST.C.Types.Fields include Steel.ST.C.Types.Base open Steel.C.Typestring open Steel.ST.Util [@@noextract_to "krml"] // tactic let norm_fields () : FStar.Tactics.Tac unit = FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops]; FStar.Tactics.trefl () [@@noextract_to "krml"] // primitive val field_t_nil: Type0 [@@noextract_to "krml"] // primitive val field_t_cons (fn: Type0) (ft: Type0) (fc: Type0): Type0 inline_for_extraction [@@noextract_to "krml"; norm_field_attr] noeq type field_description_t (t: Type0) : Type u#1 = { fd_def: (string -> GTot bool); fd_empty: (fd_empty: bool { fd_empty == true <==> (forall s . fd_def s == false) }); fd_type: (string -> Type0); fd_typedef: ((s: string) -> Pure (typedef (fd_type s)) (requires (fd_def s)) (ensures (fun _ -> True))); } inline_for_extraction [@@noextract_to "krml"; norm_field_attr] let nonempty_field_description_t (t: Type0) = (fd: field_description_t t { fd.fd_empty == false })
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.C.Types.Base.fsti.checked", "Steel.C.Typestring.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Fields.fsti" }
[ { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.C.Typestring", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.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
fd: Steel.ST.C.Types.Fields.field_description_t t -> Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.C.Types.Fields.field_description_t", "Prims.string", "Prims.b2t", "Steel.ST.C.Types.Fields.__proj__Mkfield_description_t__item__fd_def", "Prims.eqtype" ]
[]
false
false
false
true
false
let field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype =
(s: string{fd.fd_def s})
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.split_l'
val split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt
val split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt
let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i }
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 28, "end_line": 451, "start_col": 0, "start_line": 446 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array elt -> i: FStar.Ghost.erased Prims.nat {FStar.Ghost.reveal i <= Pulse.Lib.HigherArray.length a} -> Pulse.Lib.HigherArray.array elt
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.array", "FStar.Ghost.erased", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Ghost.reveal", "Pulse.Lib.HigherArray.length", "Pulse.Lib.HigherArray.Mkarray", "Pulse.Lib.HigherArray.ptr_of" ]
[]
false
false
false
false
false
let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt =
{ p = ptr_of a; length = i }
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.array_slice
val array_slice (#elt: Type) (a: array elt) (i: nat) (j: nat{i <= j /\ j <= length a}) : GTot (array elt)
val array_slice (#elt: Type) (a: array elt) (i: nat) (j: nat{i <= j /\ j <= length a}) : GTot (array elt)
let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 31, "end_line": 481, "start_col": 0, "start_line": 476 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array elt -> i: Prims.nat -> j: Prims.nat{i <= j /\ j <= Pulse.Lib.HigherArray.length a} -> Prims.GTot (Pulse.Lib.HigherArray.array elt)
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.Lib.HigherArray.array", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Pulse.Lib.HigherArray.length", "Pulse.Lib.HigherArray.split_l", "Pulse.Lib.HigherArray.split_r", "FStar.Ghost.hide", "Prims.op_Subtraction" ]
[]
false
false
false
false
false
let array_slice (#elt: Type) (a: array elt) (i: nat) (j: nat{i <= j /\ j <= length a}) : GTot (array elt) =
split_l (split_r a i) (j - i)
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.pts_to_range_split
val pts_to_range_split (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s: Seq.seq elt) : stt_ghost unit (pts_to_range a i j #p s ** pure (i <= m /\ m <= j) ) (fun _ -> exists* s1 s2. pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ** pure ( i <= m /\ m <= j /\ j <= length a /\ Seq.length s == j - i /\ s1 == Seq.slice s 0 (m - i) /\ s2 == Seq.slice s (m - i) (Seq.length s) /\ s == Seq.append s1 s2 ))
val pts_to_range_split (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s: Seq.seq elt) : stt_ghost unit (pts_to_range a i j #p s ** pure (i <= m /\ m <= j) ) (fun _ -> exists* s1 s2. pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ** pure ( i <= m /\ m <= j /\ j <= length a /\ Seq.length s == j - i /\ s1 == Seq.slice s 0 (m - i) /\ s2 == Seq.slice s (m - i) (Seq.length s) /\ s == Seq.append s1 s2 ))
let pts_to_range_split = pts_to_range_split'
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 699, "start_col": 0, "start_line": 699 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i) let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s) ```pulse ghost fn elim_in_bounds (#elt:Type) (#i #j:nat) (s:array elt) (p:in_bounds i j s) requires emp ensures pure (i <= j /\ j <= length s) { () } ``` let token (x:'a) = emp let pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop = exists* (q:in_bounds i j x). pts_to (array_slice x i j) #p s ** token q ```pulse ghost fn pts_to_range_prop' (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ensures pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ Seq.length s == j - i) ) { unfold pts_to_range a i j #p s; with q. assert (token #(in_bounds i j a) q); elim_in_bounds a q; pts_to_len (array_slice a i j); fold pts_to_range a i j #p s; } ``` let pts_to_range_prop = pts_to_range_prop' ```pulse ghost fn pts_to_range_intro' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to a #p s ensures pts_to_range a 0 (length a) #p s { rewrite each a as (array_slice a 0 (length a)); let q : in_bounds 0 (length a) a = (); fold (token #(in_bounds 0 (length a) a) q); fold (pts_to_range a 0 (length a) #p s); } ``` let pts_to_range_intro = pts_to_range_intro' ```pulse ghost fn pts_to_range_elim' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to_range a 0 (length a) #p s ensures pts_to a #p s { unfold (pts_to_range a 0 (length a) #p s); unfold (token #(in_bounds 0 (length a) a) _); rewrite each (array_slice a 0 (length a)) as a; } ``` let pts_to_range_elim = pts_to_range_elim' let mk_carrier_split (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: perm) (i: nat) (_:squash ( offset + Seq.length s <= len /\ i <= Seq.length s )) : squash ( let c1 = mk_carrier len offset (Seq.slice s 0 i) p in let c2 = mk_carrier len (offset + i) (Seq.slice s i (Seq.length s)) p in composable c1 c2 /\ mk_carrier len offset s p `Map.equal` (c1 `compose` c2) ) = () ```pulse ghost fn use_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn ghost_split (#elt: Type) (#x: Seq.seq elt) (#p: perm) (a: array elt) (i: nat {i <= length a}) requires pts_to a #p x returns _: squash (i <= length a /\ i <= Seq.length x) ensures pts_to (split_r a i) #p (Seq.slice x i (Seq.length x)) ** pts_to (split_l a i) #p (Seq.slice x 0 i) ** pure (x `Seq.equal` Seq.append (Seq.slice x 0 i) (Seq.slice x i (Seq.length x))) { unfold (pts_to a #p x); use_squash (mk_carrier_split (SZ.v (ptr_of a).base_len) (ptr_of a).offset x p i ()); let xl = Seq.slice x 0 i; let xr = Seq.slice x i (Seq.length x); let vl = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) xl p; let vr = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset + i) xr p; Pulse.Lib.Core.share (ptr_of a).base vl vr; rewrite pcm_pts_to (ptr_of a).base vl as pcm_pts_to (ptr_of (split_l a i)).base vl; rewrite pcm_pts_to (ptr_of a).base vr as pcm_pts_to (ptr_of (split_r a i)).base vr; fold (pts_to (split_l a i) #p xl); fold (pts_to (split_r a i) #p xr); } ``` let vprop_equiv_refl_eq (v0 v1:vprop) (_:squash (v0 == v1)) : vprop_equiv v0 v1 = vprop_equiv_refl v0 let equiv () : FStar.Tactics.Tac unit = let open FStar.Tactics in mapply (`vprop_equiv_refl_eq); smt() ```pulse ghost fn split_l_slice #elt (a : array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_l (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a i m) #p s { rewrite each (split_l (array_slice a i j) (m - i)) as (array_slice a i m); } ``` ```pulse ghost fn split_r_slice #elt (a:array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_r (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a m j) #p s { rewrite each (split_r (array_slice a i j) (m - i)) as (array_slice a m j); } ``` ```pulse ghost fn pts_to_range_split' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ** pure (i <= m /\ m <= j) ensures exists* s1 s2. pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ** pure ( i <= m /\ m <= j /\ j <= length a /\ eq2 #int (Seq.length s) (j - i) /\ s1 == Seq.slice s 0 (m - i) /\ s2 == Seq.slice s (m - i) (Seq.length s) /\ s == Seq.append s1 s2 ) { pts_to_range_prop a; unfold pts_to_range a i j #p s; unfold (token #(in_bounds i j a) _); ghost_split (array_slice a i j) (m - i); split_r_slice a i m j #(Seq.slice s (m - i) (Seq.length s)) (); split_l_slice a i m j (); let q1 : in_bounds i m a = (); let q2 : in_bounds m j a = (); fold (token #(in_bounds i m a) q1); fold (token #(in_bounds m j a) q2); fold (pts_to_range a i m #p (Seq.slice s 0 (m - i))); fold (pts_to_range a m j #p (Seq.slice s (m - i) (Seq.length s))); assert pure (s `Seq.equal` Seq.append (Seq.slice s 0 (m - i)) (Seq.slice s (m - i) (Seq.length s))); }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array elt -> i: Prims.nat -> m: Prims.nat -> j: Prims.nat -> Pulse.Lib.Core.stt_ghost Prims.unit (Pulse.Lib.HigherArray.pts_to_range a i j s ** Pulse.Lib.Core.pure (i <= m /\ m <= j)) (fun _ -> exists* (s1: FStar.Seq.Base.seq elt) (s2: FStar.Seq.Base.seq elt). (Pulse.Lib.HigherArray.pts_to_range a i m s1 ** Pulse.Lib.HigherArray.pts_to_range a m j s2) ** Pulse.Lib.Core.pure (i <= m /\ m <= j /\ j <= Pulse.Lib.HigherArray.length a /\ FStar.Seq.Base.length s == j - i /\ s1 == FStar.Seq.Base.slice s 0 (m - i) /\ s2 == FStar.Seq.Base.slice s (m - i) (FStar.Seq.Base.length s) /\ s == FStar.Seq.Base.append s1 s2))
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.pts_to_range_split'" ]
[]
false
false
false
false
false
let pts_to_range_split =
pts_to_range_split'
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.vprop_equiv_refl_eq
val vprop_equiv_refl_eq: v0: vprop -> v1: vprop -> squash (v0 == v1) -> vprop_equiv v0 v1
val vprop_equiv_refl_eq: v0: vprop -> v1: vprop -> squash (v0 == v1) -> vprop_equiv v0 v1
let vprop_equiv_refl_eq (v0 v1:vprop) (_:squash (v0 == v1)) : vprop_equiv v0 v1 = vprop_equiv_refl v0
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 21, "end_line": 625, "start_col": 0, "start_line": 624 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i) let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s) ```pulse ghost fn elim_in_bounds (#elt:Type) (#i #j:nat) (s:array elt) (p:in_bounds i j s) requires emp ensures pure (i <= j /\ j <= length s) { () } ``` let token (x:'a) = emp let pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop = exists* (q:in_bounds i j x). pts_to (array_slice x i j) #p s ** token q ```pulse ghost fn pts_to_range_prop' (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ensures pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ Seq.length s == j - i) ) { unfold pts_to_range a i j #p s; with q. assert (token #(in_bounds i j a) q); elim_in_bounds a q; pts_to_len (array_slice a i j); fold pts_to_range a i j #p s; } ``` let pts_to_range_prop = pts_to_range_prop' ```pulse ghost fn pts_to_range_intro' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to a #p s ensures pts_to_range a 0 (length a) #p s { rewrite each a as (array_slice a 0 (length a)); let q : in_bounds 0 (length a) a = (); fold (token #(in_bounds 0 (length a) a) q); fold (pts_to_range a 0 (length a) #p s); } ``` let pts_to_range_intro = pts_to_range_intro' ```pulse ghost fn pts_to_range_elim' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to_range a 0 (length a) #p s ensures pts_to a #p s { unfold (pts_to_range a 0 (length a) #p s); unfold (token #(in_bounds 0 (length a) a) _); rewrite each (array_slice a 0 (length a)) as a; } ``` let pts_to_range_elim = pts_to_range_elim' let mk_carrier_split (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: perm) (i: nat) (_:squash ( offset + Seq.length s <= len /\ i <= Seq.length s )) : squash ( let c1 = mk_carrier len offset (Seq.slice s 0 i) p in let c2 = mk_carrier len (offset + i) (Seq.slice s i (Seq.length s)) p in composable c1 c2 /\ mk_carrier len offset s p `Map.equal` (c1 `compose` c2) ) = () ```pulse ghost fn use_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn ghost_split (#elt: Type) (#x: Seq.seq elt) (#p: perm) (a: array elt) (i: nat {i <= length a}) requires pts_to a #p x returns _: squash (i <= length a /\ i <= Seq.length x) ensures pts_to (split_r a i) #p (Seq.slice x i (Seq.length x)) ** pts_to (split_l a i) #p (Seq.slice x 0 i) ** pure (x `Seq.equal` Seq.append (Seq.slice x 0 i) (Seq.slice x i (Seq.length x))) { unfold (pts_to a #p x); use_squash (mk_carrier_split (SZ.v (ptr_of a).base_len) (ptr_of a).offset x p i ()); let xl = Seq.slice x 0 i; let xr = Seq.slice x i (Seq.length x); let vl = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) xl p; let vr = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset + i) xr p; Pulse.Lib.Core.share (ptr_of a).base vl vr; rewrite pcm_pts_to (ptr_of a).base vl as pcm_pts_to (ptr_of (split_l a i)).base vl; rewrite pcm_pts_to (ptr_of a).base vr as pcm_pts_to (ptr_of (split_r a i)).base vr; fold (pts_to (split_l a i) #p xl); fold (pts_to (split_r a i) #p xr); } ```
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v0: Pulse.Lib.Core.vprop -> v1: Pulse.Lib.Core.vprop -> _: Prims.squash (v0 == v1) -> Pulse.Lib.Core.vprop_equiv v0 v1
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Core.vprop", "Prims.squash", "Prims.eq2", "Pulse.Lib.Core.vprop_equiv_refl", "Pulse.Lib.Core.vprop_equiv" ]
[]
false
false
false
false
false
let vprop_equiv_refl_eq (v0: vprop) (v1: vprop) (_: squash (v0 == v1)) : vprop_equiv v0 v1 =
vprop_equiv_refl v0
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.pts_to_range_prop
val pts_to_range_prop (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) : stt_ghost unit (pts_to_range a i j #p s) (fun _ -> pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ eq2 #nat (Seq.length s) (j - i)) ))
val pts_to_range_prop (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) : stt_ghost unit (pts_to_range a i j #p s) (fun _ -> pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ eq2 #nat (Seq.length s) (j - i)) ))
let pts_to_range_prop = pts_to_range_prop'
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 526, "start_col": 0, "start_line": 526 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i) let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s) ```pulse ghost fn elim_in_bounds (#elt:Type) (#i #j:nat) (s:array elt) (p:in_bounds i j s) requires emp ensures pure (i <= j /\ j <= length s) { () } ``` let token (x:'a) = emp let pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop = exists* (q:in_bounds i j x). pts_to (array_slice x i j) #p s ** token q ```pulse ghost fn pts_to_range_prop' (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ensures pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ Seq.length s == j - i) ) { unfold pts_to_range a i j #p s; with q. assert (token #(in_bounds i j a) q); elim_in_bounds a q; pts_to_len (array_slice a i j); fold pts_to_range a i j #p s; }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array elt -> Pulse.Lib.Core.stt_ghost Prims.unit (Pulse.Lib.HigherArray.pts_to_range a i j s) (fun _ -> Pulse.Lib.HigherArray.pts_to_range a i j s ** Pulse.Lib.Core.pure (i <= j /\ j <= Pulse.Lib.HigherArray.length a /\ FStar.Seq.Base.length s == j - i))
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.pts_to_range_prop'" ]
[]
false
false
false
false
false
let pts_to_range_prop =
pts_to_range_prop'
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.mk_carrier_gather
val mk_carrier_gather: #elt: Type -> len: nat -> offset: nat -> s1: Seq.seq elt -> s2: Seq.seq elt -> p1: perm -> p2: perm -> squash (let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len) -> squash (let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2)
val mk_carrier_gather: #elt: Type -> len: nat -> offset: nat -> s1: Seq.seq elt -> s2: Seq.seq elt -> p1: perm -> p2: perm -> squash (let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len) -> squash (let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2)
let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2)
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 71, "end_line": 382, "start_col": 0, "start_line": 355 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share'
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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
len: Prims.nat -> offset: Prims.nat -> s1: FStar.Seq.Base.seq elt -> s2: FStar.Seq.Base.seq elt -> p1: PulseCore.FractionalPermission.perm -> p2: PulseCore.FractionalPermission.perm -> _: Prims.squash (let c1 = Pulse.Lib.PCM.Array.mk_carrier len offset s1 p1 in let c2 = Pulse.Lib.PCM.Array.mk_carrier len offset s2 p2 in Pulse.Lib.PCM.Array.composable c1 c2 /\ FStar.Seq.Base.length s1 == FStar.Seq.Base.length s2 /\ offset + FStar.Seq.Base.length s1 <= len) -> Prims.squash (let c1 = Pulse.Lib.PCM.Array.mk_carrier len offset s1 p1 in let c2 = Pulse.Lib.PCM.Array.mk_carrier len offset s2 p2 in Pulse.Lib.PCM.Array.composable c1 c2 /\ Pulse.Lib.PCM.Array.mk_carrier len offset s1 (PulseCore.FractionalPermission.sum_perm p1 p2) == Pulse.Lib.PCM.Array.compose c1 c2 /\ Pulse.Lib.PCM.Array.mk_carrier len offset s2 (PulseCore.FractionalPermission.sum_perm p1 p2) == Pulse.Lib.PCM.Array.compose c1 c2 /\ s1 == s2)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.Seq.Base.seq", "PulseCore.FractionalPermission.perm", "Prims.squash", "Prims.l_and", "Pulse.Lib.PCM.Array.composable", "FStar.Ghost.hide", "Prims.eq2", "FStar.Seq.Base.length", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Pulse.Lib.PCM.Array.carrier", "Pulse.Lib.PCM.Array.mk_carrier", "Pulse.Lib.PCM.Array.mk_carrier_inj", "PulseCore.FractionalPermission.sum_perm", "Prims.unit", "Prims._assert", "FStar.Map.equal", "Pulse.Lib.PCM.Array.index_t", "Pulse.Lib.PCM.Fraction.fractional", "Pulse.Lib.PCM.Array.compose" ]
[]
false
false
true
false
false
let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1: Seq.seq elt) (s2: Seq.seq elt) (p1: perm) (p2: perm) (_: squash (let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len)) : squash (let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2) =
let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert ((mk_carrier len offset s1 (p1 `sum_perm` p2)) `Map.equal` (c1 `compose` c2)); assert ((mk_carrier len offset s2 (p1 `sum_perm` p2)) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2)
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.op_Array_Access
val op_Array_Access (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) : stt t (requires pts_to a #p s) (ensures fun res -> pts_to a #p s ** pure (res == Seq.index s (SZ.v i)))
val op_Array_Access (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) : stt t (requires pts_to a #p s) (ensures fun res -> pts_to a #p s ** pure (res == Seq.index s (SZ.v i)))
let op_Array_Access = read
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 26, "end_line": 219, "start_col": 0, "start_line": 219 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array t -> i: FStar.SizeT.t -> Pulse.Lib.Core.stt t (Pulse.Lib.HigherArray.pts_to a (FStar.Ghost.reveal s)) (fun res -> Pulse.Lib.HigherArray.pts_to a (FStar.Ghost.reveal s) ** Pulse.Lib.Core.pure (res == FStar.Seq.Base.index (FStar.Ghost.reveal s) (FStar.SizeT.v i)) )
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.read" ]
[]
false
false
false
false
false
let op_Array_Access =
read
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.mk_carrier_valid_sum_perm
val mk_carrier_valid_sum_perm (#elt: Type) (len offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2)
val mk_carrier_valid_sum_perm (#elt: Type) (len offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2)
let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else ()
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 9, "end_line": 401, "start_col": 0, "start_line": 385 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2)
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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
len: Prims.nat -> offset: Prims.nat -> s: FStar.Seq.Base.seq elt -> p1: PulseCore.FractionalPermission.perm -> p2: PulseCore.FractionalPermission.perm -> Prims.squash (let c1 = Pulse.Lib.PCM.Array.mk_carrier len offset s p1 in let c2 = Pulse.Lib.PCM.Array.mk_carrier len offset s p2 in Pulse.Lib.PCM.Array.composable c1 c2 <==> Pulse.Lib.HigherArray.valid_sum_perm len offset (FStar.Seq.Base.length s) p1 p2)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.Seq.Base.seq", "PulseCore.FractionalPermission.perm", "Prims.op_AmpAmp", "Prims.op_GreaterThan", "FStar.Seq.Base.length", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Prims._assert", "Prims.l_iff", "Pulse.Lib.PCM.Fraction.composable", "FStar.Map.sel", "Pulse.Lib.PCM.Array.index_t", "FStar.Ghost.hide", "Pulse.Lib.PCM.Fraction.fractional", "Pulse.Lib.HigherArray.valid_perm", "PulseCore.FractionalPermission.sum_perm", "Prims.bool", "Prims.squash", "Pulse.Lib.PCM.Array.composable", "Pulse.Lib.HigherArray.valid_sum_perm", "Pulse.Lib.PCM.Array.carrier", "Pulse.Lib.PCM.Array.mk_carrier" ]
[]
false
false
true
false
false
let mk_carrier_valid_sum_perm (#elt: Type) (len offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) =
let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2))
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.merge'
val merge' : a1: Pulse.Lib.HigherArray.array elt -> a2: Pulse.Lib.HigherArray.array elt {Pulse.Lib.HigherArray.adjacent a1 a2} -> Pulse.Lib.HigherArray.array elt
let merge' (#elt: Type) (a1: array elt) (a2:array elt { adjacent a1 a2 }) = { p = ptr_of a1; length=Ghost.hide (length a1 + length a2) }
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 62, "end_line": 724, "start_col": 0, "start_line": 723 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i) let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s) ```pulse ghost fn elim_in_bounds (#elt:Type) (#i #j:nat) (s:array elt) (p:in_bounds i j s) requires emp ensures pure (i <= j /\ j <= length s) { () } ``` let token (x:'a) = emp let pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop = exists* (q:in_bounds i j x). pts_to (array_slice x i j) #p s ** token q ```pulse ghost fn pts_to_range_prop' (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ensures pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ Seq.length s == j - i) ) { unfold pts_to_range a i j #p s; with q. assert (token #(in_bounds i j a) q); elim_in_bounds a q; pts_to_len (array_slice a i j); fold pts_to_range a i j #p s; } ``` let pts_to_range_prop = pts_to_range_prop' ```pulse ghost fn pts_to_range_intro' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to a #p s ensures pts_to_range a 0 (length a) #p s { rewrite each a as (array_slice a 0 (length a)); let q : in_bounds 0 (length a) a = (); fold (token #(in_bounds 0 (length a) a) q); fold (pts_to_range a 0 (length a) #p s); } ``` let pts_to_range_intro = pts_to_range_intro' ```pulse ghost fn pts_to_range_elim' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to_range a 0 (length a) #p s ensures pts_to a #p s { unfold (pts_to_range a 0 (length a) #p s); unfold (token #(in_bounds 0 (length a) a) _); rewrite each (array_slice a 0 (length a)) as a; } ``` let pts_to_range_elim = pts_to_range_elim' let mk_carrier_split (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: perm) (i: nat) (_:squash ( offset + Seq.length s <= len /\ i <= Seq.length s )) : squash ( let c1 = mk_carrier len offset (Seq.slice s 0 i) p in let c2 = mk_carrier len (offset + i) (Seq.slice s i (Seq.length s)) p in composable c1 c2 /\ mk_carrier len offset s p `Map.equal` (c1 `compose` c2) ) = () ```pulse ghost fn use_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn ghost_split (#elt: Type) (#x: Seq.seq elt) (#p: perm) (a: array elt) (i: nat {i <= length a}) requires pts_to a #p x returns _: squash (i <= length a /\ i <= Seq.length x) ensures pts_to (split_r a i) #p (Seq.slice x i (Seq.length x)) ** pts_to (split_l a i) #p (Seq.slice x 0 i) ** pure (x `Seq.equal` Seq.append (Seq.slice x 0 i) (Seq.slice x i (Seq.length x))) { unfold (pts_to a #p x); use_squash (mk_carrier_split (SZ.v (ptr_of a).base_len) (ptr_of a).offset x p i ()); let xl = Seq.slice x 0 i; let xr = Seq.slice x i (Seq.length x); let vl = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) xl p; let vr = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset + i) xr p; Pulse.Lib.Core.share (ptr_of a).base vl vr; rewrite pcm_pts_to (ptr_of a).base vl as pcm_pts_to (ptr_of (split_l a i)).base vl; rewrite pcm_pts_to (ptr_of a).base vr as pcm_pts_to (ptr_of (split_r a i)).base vr; fold (pts_to (split_l a i) #p xl); fold (pts_to (split_r a i) #p xr); } ``` let vprop_equiv_refl_eq (v0 v1:vprop) (_:squash (v0 == v1)) : vprop_equiv v0 v1 = vprop_equiv_refl v0 let equiv () : FStar.Tactics.Tac unit = let open FStar.Tactics in mapply (`vprop_equiv_refl_eq); smt() ```pulse ghost fn split_l_slice #elt (a : array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_l (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a i m) #p s { rewrite each (split_l (array_slice a i j) (m - i)) as (array_slice a i m); } ``` ```pulse ghost fn split_r_slice #elt (a:array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_r (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a m j) #p s { rewrite each (split_r (array_slice a i j) (m - i)) as (array_slice a m j); } ``` ```pulse ghost fn pts_to_range_split' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ** pure (i <= m /\ m <= j) ensures exists* s1 s2. pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ** pure ( i <= m /\ m <= j /\ j <= length a /\ eq2 #int (Seq.length s) (j - i) /\ s1 == Seq.slice s 0 (m - i) /\ s2 == Seq.slice s (m - i) (Seq.length s) /\ s == Seq.append s1 s2 ) { pts_to_range_prop a; unfold pts_to_range a i j #p s; unfold (token #(in_bounds i j a) _); ghost_split (array_slice a i j) (m - i); split_r_slice a i m j #(Seq.slice s (m - i) (Seq.length s)) (); split_l_slice a i m j (); let q1 : in_bounds i m a = (); let q2 : in_bounds m j a = (); fold (token #(in_bounds i m a) q1); fold (token #(in_bounds m j a) q2); fold (pts_to_range a i m #p (Seq.slice s 0 (m - i))); fold (pts_to_range a m j #p (Seq.slice s (m - i) (Seq.length s))); assert pure (s `Seq.equal` Seq.append (Seq.slice s 0 (m - i)) (Seq.slice s (m - i) (Seq.length s))); } ``` let pts_to_range_split = pts_to_range_split' let mk_carrier_merge (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p: perm) (_:squash ( offset + Seq.length s1 + Seq.length s2 <= len )) : squash ( let c1 = mk_carrier len offset s1 p in let c2 = mk_carrier len (offset + Seq.length s1) s2 p in composable c1 c2 /\ mk_carrier len offset (s1 `Seq.append` s2) p `Map.equal` (c1 `compose` c2) ) = () let adjacent (#elt: Type) (a1 a2: array elt) : Tot prop = base (ptr_of a1) == base (ptr_of a2) /\ offset (ptr_of a1) + (length a1) == offset (ptr_of a2)
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a1: Pulse.Lib.HigherArray.array elt -> a2: Pulse.Lib.HigherArray.array elt {Pulse.Lib.HigherArray.adjacent a1 a2} -> Pulse.Lib.HigherArray.array elt
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.array", "Pulse.Lib.HigherArray.adjacent", "Pulse.Lib.HigherArray.Mkarray", "Pulse.Lib.HigherArray.ptr_of", "FStar.Ghost.hide", "Prims.nat", "Prims.op_Addition", "Pulse.Lib.HigherArray.length" ]
[]
false
false
false
false
false
let merge' (#elt: Type) (a1: array elt) (a2: array elt {adjacent a1 a2}) =
{ p = ptr_of a1; length = Ghost.hide (length a1 + length a2) }
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.split_r'
val split_r' (#elt: Type) (a: array elt) (i: nat{i <= length a}) : array elt
val split_r' (#elt: Type) (a: array elt) (i: nat{i <= length a}) : array elt
let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) }
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 65, "end_line": 466, "start_col": 0, "start_line": 461 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array elt -> i: Prims.nat{i <= Pulse.Lib.HigherArray.length a} -> Pulse.Lib.HigherArray.array elt
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.array", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Pulse.Lib.HigherArray.length", "Pulse.Lib.HigherArray.Mkarray", "Pulse.Lib.HigherArray.ptr_shift", "Pulse.Lib.HigherArray.ptr_of", "FStar.Ghost.hide", "Prims.op_Subtraction" ]
[]
false
false
false
false
false
let split_r' (#elt: Type) (a: array elt) (i: nat{i <= length a}) : array elt =
{ p = ptr_shift (ptr_of a) i; length = Ghost.hide (length a - i) }
false
FStar.Tactics.MApply.fst
FStar.Tactics.MApply.termable_binding
[@@ FStar.Tactics.Typeclasses.tcinstance] val termable_binding:termable binding
[@@ FStar.Tactics.Typeclasses.tcinstance] val termable_binding:termable binding
instance termable_binding : termable binding = { to_term = (fun b -> binding_to_term b); }
{ "file_name": "ulib/FStar.Tactics.MApply.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 1, "end_line": 103, "start_col": 0, "start_line": 101 }
module FStar.Tactics.MApply open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxHelpers open FStar.Tactics.V2.Derived open FStar.Tactics.V2.SyntaxCoercions open FStar.Tactics.Typeclasses private val push1 : (#p:Type) -> (#q:Type) -> squash (p ==> q) -> squash p -> squash q private let push1 #p #q f u = () private val push1' : (#p:Type) -> (#q:Type) -> (p ==> q) -> squash p -> squash q private let push1' #p #q f u = () (* * Some easier applying, which should prevent frustration * (or cause more when it doesn't do what you wanted to) *) val apply_squash_or_lem : d:nat -> term -> Tac unit let rec apply_squash_or_lem d t = (* Before anything, try a vanilla apply and apply_lemma *) try apply t with | _ -> try apply (`FStar.Squash.return_squash); apply t with | _ -> try apply_lemma t with | _ -> // Fuel cutoff, just in case. if d <= 0 then fail "mapply: out of fuel" else begin let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> begin let post = `((`#post) ()) in (* unthunk *) let post = norm_term [] post in (* Is the lemma an implication? We can try to intro *) match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end | C_Total rt -> begin match unsquash_term rt with (* If the function returns a squash, just apply it, since our goals are squashed *) | Some rt -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end (* If not, we can try to introduce the squash ourselves first *) | None -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> apply (`FStar.Squash.return_squash); apply t end end | _ -> fail "mapply: can't apply (2)" end class termable (a : Type) = { to_term : a -> Tac term } instance termable_term : termable term = { to_term = (fun t -> t); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Tactics.MApply.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.Derived", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "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
FStar.Tactics.MApply.termable FStar.Tactics.NamedView.binding
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.MApply.Mktermable", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.SyntaxCoercions.binding_to_term", "FStar.Tactics.NamedView.term" ]
[]
false
false
false
true
false
[@@ FStar.Tactics.Typeclasses.tcinstance] let termable_binding:termable binding =
{ to_term = (fun b -> binding_to_term b) }
false
FStar.Tactics.MApply.fst
FStar.Tactics.MApply.termable_term
[@@ FStar.Tactics.Typeclasses.tcinstance] val termable_term:termable term
[@@ FStar.Tactics.Typeclasses.tcinstance] val termable_term:termable term
instance termable_term : termable term = { to_term = (fun t -> t); }
{ "file_name": "ulib/FStar.Tactics.MApply.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 1, "end_line": 99, "start_col": 0, "start_line": 97 }
module FStar.Tactics.MApply open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxHelpers open FStar.Tactics.V2.Derived open FStar.Tactics.V2.SyntaxCoercions open FStar.Tactics.Typeclasses private val push1 : (#p:Type) -> (#q:Type) -> squash (p ==> q) -> squash p -> squash q private let push1 #p #q f u = () private val push1' : (#p:Type) -> (#q:Type) -> (p ==> q) -> squash p -> squash q private let push1' #p #q f u = () (* * Some easier applying, which should prevent frustration * (or cause more when it doesn't do what you wanted to) *) val apply_squash_or_lem : d:nat -> term -> Tac unit let rec apply_squash_or_lem d t = (* Before anything, try a vanilla apply and apply_lemma *) try apply t with | _ -> try apply (`FStar.Squash.return_squash); apply t with | _ -> try apply_lemma t with | _ -> // Fuel cutoff, just in case. if d <= 0 then fail "mapply: out of fuel" else begin let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> begin let post = `((`#post) ()) in (* unthunk *) let post = norm_term [] post in (* Is the lemma an implication? We can try to intro *) match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end | C_Total rt -> begin match unsquash_term rt with (* If the function returns a squash, just apply it, since our goals are squashed *) | Some rt -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end (* If not, we can try to introduce the squash ourselves first *) | None -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> apply (`FStar.Squash.return_squash); apply t end end | _ -> fail "mapply: can't apply (2)" end class termable (a : Type) = { to_term : a -> Tac term }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Tactics.MApply.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.Derived", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "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
FStar.Tactics.MApply.termable FStar.Tactics.NamedView.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.MApply.Mktermable", "FStar.Tactics.NamedView.term" ]
[]
false
false
false
true
false
[@@ FStar.Tactics.Typeclasses.tcinstance] let termable_term:termable term =
{ to_term = (fun t -> t) }
false
Steel.ST.Reference.fst
Steel.ST.Reference.is_null
val is_null (#a:Type0) (r:ref a) : b:bool{b <==> r == null}
val is_null (#a:Type0) (r:ref a) : b:bool{b <==> r == null}
let is_null (#a:Type0) (r:ref a) : b:bool{b <==> r == null} = R.is_null r
{ "file_name": "lib/steel/Steel.ST.Reference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 15, "end_line": 33, "start_col": 0, "start_line": 31 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Reference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference let ref (a:Type0) : Type0 = R.ref a let null (#a:Type0) : ref a = R.null #a
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Reference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.ST.Reference.ref a -> b: Prims.bool{b <==> r == Steel.ST.Reference.null}
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.Reference.ref", "Steel.Reference.is_null", "Prims.bool", "Prims.l_iff", "Prims.b2t", "Prims.eq2", "Steel.ST.Reference.null" ]
[]
false
false
false
false
false
let is_null (#a: Type0) (r: ref a) : b: bool{b <==> r == null} =
R.is_null r
false
FStar.Tactics.MApply.fst
FStar.Tactics.MApply.mapply0
val mapply0 (t: term) : Tac unit
val mapply0 (t: term) : Tac unit
let mapply0 (t : term) : Tac unit = apply_squash_or_lem 10 t
{ "file_name": "ulib/FStar.Tactics.MApply.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 107, "start_col": 0, "start_line": 106 }
module FStar.Tactics.MApply open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxHelpers open FStar.Tactics.V2.Derived open FStar.Tactics.V2.SyntaxCoercions open FStar.Tactics.Typeclasses private val push1 : (#p:Type) -> (#q:Type) -> squash (p ==> q) -> squash p -> squash q private let push1 #p #q f u = () private val push1' : (#p:Type) -> (#q:Type) -> (p ==> q) -> squash p -> squash q private let push1' #p #q f u = () (* * Some easier applying, which should prevent frustration * (or cause more when it doesn't do what you wanted to) *) val apply_squash_or_lem : d:nat -> term -> Tac unit let rec apply_squash_or_lem d t = (* Before anything, try a vanilla apply and apply_lemma *) try apply t with | _ -> try apply (`FStar.Squash.return_squash); apply t with | _ -> try apply_lemma t with | _ -> // Fuel cutoff, just in case. if d <= 0 then fail "mapply: out of fuel" else begin let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> begin let post = `((`#post) ()) in (* unthunk *) let post = norm_term [] post in (* Is the lemma an implication? We can try to intro *) match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end | C_Total rt -> begin match unsquash_term rt with (* If the function returns a squash, just apply it, since our goals are squashed *) | Some rt -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end (* If not, we can try to introduce the squash ourselves first *) | None -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> apply (`FStar.Squash.return_squash); apply t end end | _ -> fail "mapply: can't apply (2)" end class termable (a : Type) = { to_term : a -> Tac term } instance termable_term : termable term = { to_term = (fun t -> t); } instance termable_binding : termable binding = { to_term = (fun b -> binding_to_term b); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Tactics.MApply.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.Derived", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "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 Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Tactics.MApply.apply_squash_or_lem", "Prims.unit" ]
[]
false
true
false
false
false
let mapply0 (t: term) : Tac unit =
apply_squash_or_lem 10 t
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.pts_to_range_index
val pts_to_range_index (#t: Type) (a: array t) (i: SZ.t) (#l: Ghost.erased nat{l <= SZ.v i}) (#r: Ghost.erased nat{SZ.v i < r}) (#s: Ghost.erased (Seq.seq t)) (#p: perm) : stt t (requires pts_to_range a l r #p s) (ensures fun res -> pts_to_range a l r #p s ** pure (Seq.length s == r - l /\ res == Seq.index s (SZ.v i - l)))
val pts_to_range_index (#t: Type) (a: array t) (i: SZ.t) (#l: Ghost.erased nat{l <= SZ.v i}) (#r: Ghost.erased nat{SZ.v i < r}) (#s: Ghost.erased (Seq.seq t)) (#p: perm) : stt t (requires pts_to_range a l r #p s) (ensures fun res -> pts_to_range a l r #p s ** pure (Seq.length s == r - l /\ res == Seq.index s (SZ.v i - l)))
let pts_to_range_index = pts_to_range_index'
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 841, "start_col": 0, "start_line": 841 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i) let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s) ```pulse ghost fn elim_in_bounds (#elt:Type) (#i #j:nat) (s:array elt) (p:in_bounds i j s) requires emp ensures pure (i <= j /\ j <= length s) { () } ``` let token (x:'a) = emp let pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop = exists* (q:in_bounds i j x). pts_to (array_slice x i j) #p s ** token q ```pulse ghost fn pts_to_range_prop' (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ensures pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ Seq.length s == j - i) ) { unfold pts_to_range a i j #p s; with q. assert (token #(in_bounds i j a) q); elim_in_bounds a q; pts_to_len (array_slice a i j); fold pts_to_range a i j #p s; } ``` let pts_to_range_prop = pts_to_range_prop' ```pulse ghost fn pts_to_range_intro' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to a #p s ensures pts_to_range a 0 (length a) #p s { rewrite each a as (array_slice a 0 (length a)); let q : in_bounds 0 (length a) a = (); fold (token #(in_bounds 0 (length a) a) q); fold (pts_to_range a 0 (length a) #p s); } ``` let pts_to_range_intro = pts_to_range_intro' ```pulse ghost fn pts_to_range_elim' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to_range a 0 (length a) #p s ensures pts_to a #p s { unfold (pts_to_range a 0 (length a) #p s); unfold (token #(in_bounds 0 (length a) a) _); rewrite each (array_slice a 0 (length a)) as a; } ``` let pts_to_range_elim = pts_to_range_elim' let mk_carrier_split (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: perm) (i: nat) (_:squash ( offset + Seq.length s <= len /\ i <= Seq.length s )) : squash ( let c1 = mk_carrier len offset (Seq.slice s 0 i) p in let c2 = mk_carrier len (offset + i) (Seq.slice s i (Seq.length s)) p in composable c1 c2 /\ mk_carrier len offset s p `Map.equal` (c1 `compose` c2) ) = () ```pulse ghost fn use_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn ghost_split (#elt: Type) (#x: Seq.seq elt) (#p: perm) (a: array elt) (i: nat {i <= length a}) requires pts_to a #p x returns _: squash (i <= length a /\ i <= Seq.length x) ensures pts_to (split_r a i) #p (Seq.slice x i (Seq.length x)) ** pts_to (split_l a i) #p (Seq.slice x 0 i) ** pure (x `Seq.equal` Seq.append (Seq.slice x 0 i) (Seq.slice x i (Seq.length x))) { unfold (pts_to a #p x); use_squash (mk_carrier_split (SZ.v (ptr_of a).base_len) (ptr_of a).offset x p i ()); let xl = Seq.slice x 0 i; let xr = Seq.slice x i (Seq.length x); let vl = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) xl p; let vr = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset + i) xr p; Pulse.Lib.Core.share (ptr_of a).base vl vr; rewrite pcm_pts_to (ptr_of a).base vl as pcm_pts_to (ptr_of (split_l a i)).base vl; rewrite pcm_pts_to (ptr_of a).base vr as pcm_pts_to (ptr_of (split_r a i)).base vr; fold (pts_to (split_l a i) #p xl); fold (pts_to (split_r a i) #p xr); } ``` let vprop_equiv_refl_eq (v0 v1:vprop) (_:squash (v0 == v1)) : vprop_equiv v0 v1 = vprop_equiv_refl v0 let equiv () : FStar.Tactics.Tac unit = let open FStar.Tactics in mapply (`vprop_equiv_refl_eq); smt() ```pulse ghost fn split_l_slice #elt (a : array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_l (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a i m) #p s { rewrite each (split_l (array_slice a i j) (m - i)) as (array_slice a i m); } ``` ```pulse ghost fn split_r_slice #elt (a:array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_r (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a m j) #p s { rewrite each (split_r (array_slice a i j) (m - i)) as (array_slice a m j); } ``` ```pulse ghost fn pts_to_range_split' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ** pure (i <= m /\ m <= j) ensures exists* s1 s2. pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ** pure ( i <= m /\ m <= j /\ j <= length a /\ eq2 #int (Seq.length s) (j - i) /\ s1 == Seq.slice s 0 (m - i) /\ s2 == Seq.slice s (m - i) (Seq.length s) /\ s == Seq.append s1 s2 ) { pts_to_range_prop a; unfold pts_to_range a i j #p s; unfold (token #(in_bounds i j a) _); ghost_split (array_slice a i j) (m - i); split_r_slice a i m j #(Seq.slice s (m - i) (Seq.length s)) (); split_l_slice a i m j (); let q1 : in_bounds i m a = (); let q2 : in_bounds m j a = (); fold (token #(in_bounds i m a) q1); fold (token #(in_bounds m j a) q2); fold (pts_to_range a i m #p (Seq.slice s 0 (m - i))); fold (pts_to_range a m j #p (Seq.slice s (m - i) (Seq.length s))); assert pure (s `Seq.equal` Seq.append (Seq.slice s 0 (m - i)) (Seq.slice s (m - i) (Seq.length s))); } ``` let pts_to_range_split = pts_to_range_split' let mk_carrier_merge (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p: perm) (_:squash ( offset + Seq.length s1 + Seq.length s2 <= len )) : squash ( let c1 = mk_carrier len offset s1 p in let c2 = mk_carrier len (offset + Seq.length s1) s2 p in composable c1 c2 /\ mk_carrier len offset (s1 `Seq.append` s2) p `Map.equal` (c1 `compose` c2) ) = () let adjacent (#elt: Type) (a1 a2: array elt) : Tot prop = base (ptr_of a1) == base (ptr_of a2) /\ offset (ptr_of a1) + (length a1) == offset (ptr_of a2) let merge' (#elt: Type) (a1: array elt) (a2:array elt { adjacent a1 a2 }) = { p = ptr_of a1; length=Ghost.hide (length a1 + length a2) } irreducible let merge #elt a1 a2 : i:array elt{ i == merge' a1 a2 } = merge' a1 a2 ```pulse ghost fn ghost_join (#elt: Type) (#x1 #x2: Seq.seq elt) (#p: perm) (a1 a2: array elt) (h: squash (adjacent a1 a2)) requires pts_to a1 #p x1 ** pts_to a2 #p x2 ensures pts_to (merge a1 a2) #p (x1 `Seq.append` x2) { unfold pts_to a1 #p x1; unfold pts_to a2 #p x2; use_squash (mk_carrier_merge (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 x2 p ()); with w. rewrite pcm_pts_to (ptr_of a2).base w as pcm_pts_to (ptr_of a1).base (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 p); Pulse.Lib.Core.gather (ptr_of a1).base (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 (p)) (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 (p)); with w. rewrite pcm_pts_to (ptr_of a1).base w as pcm_pts_to (ptr_of (merge a1 a2)).base (mk_carrier (SZ.v (ptr_of (merge a1 a2)).base_len) ((ptr_of (merge a1 a2)).offset) (x1 `Seq.append` x2) (p)); fold (pts_to (merge a1 a2) #p (Seq.append x1 x2)); } ``` ```pulse ghost fn pts_to_range_intro_ij (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) (i j: nat) (_:squash (i <= j /\ j <= length a)) requires pts_to (array_slice a i j) #p s ensures pts_to_range a i j #p s { let q : in_bounds i j a = (); fold (token #(in_bounds i j a) q); fold (pts_to_range a i j #p s); } ``` ```pulse ghost fn pts_to_range_join' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s1 #s2: Seq.seq elt) requires pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ensures pts_to_range a i j #p (s1 `Seq.append` s2) { pts_to_range_prop a #i #m; pts_to_range_prop a #m #j; unfold pts_to_range a i m #p s1; unfold pts_to_range a m j #p s2; ghost_join (array_slice a i m) (array_slice a m j) (); rewrite each (merge (array_slice a i m) (array_slice a m j)) as (array_slice a i j); pts_to_range_intro_ij a _ _ i j (); unfold (token #(in_bounds i m a) _); unfold (token #(in_bounds m j a) _); } ``` let pts_to_range_join = pts_to_range_join' irreducible let array_slice_impl (#elt: Type) (a: array elt) (i: SZ.t) (j: Ghost.erased nat) (sq: squash (SZ.v i <= j /\ j <= length a)) : x:array elt { x == array_slice a (SZ.v i) j } = split_l (split_r a (SZ.v i)) (Ghost.hide (j - SZ.v i)) ```pulse fn pts_to_range_index' (#t: Type) (a: array t) (i: SZ.t) (#l: Ghost.erased nat{l <= SZ.v i}) (#r: Ghost.erased nat{SZ.v i < r}) (#s: Ghost.erased (Seq.seq t)) (#p: perm) requires pts_to_range a l r #p s returns res:t ensures pts_to_range a l r #p s ** pure (eq2 #int (Seq.length s) (r - l) /\ res == Seq.index s (SZ.v i - l)) { pts_to_range_split a l (SZ.v i) r; with s1 s2. _; unfold pts_to_range a (SZ.v i) r #p s2; unfold (token #(in_bounds (SZ.v i) r a) _); let a' = array_slice_impl a i r (); rewrite each (array_slice a (SZ.v i) r) as a'; let res = read a' 0sz; rewrite each a' as (array_slice a (SZ.v i) r); pts_to_range_intro_ij a _ _ (SZ.v i) r (); pts_to_range_join a l (SZ.v i) r; res }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array t -> i: FStar.SizeT.t -> Pulse.Lib.Core.stt t (Pulse.Lib.HigherArray.pts_to_range a (FStar.Ghost.reveal l) (FStar.Ghost.reveal r) (FStar.Ghost.reveal s)) (fun res -> Pulse.Lib.HigherArray.pts_to_range a (FStar.Ghost.reveal l) (FStar.Ghost.reveal r) (FStar.Ghost.reveal s) ** Pulse.Lib.Core.pure (FStar.Seq.Base.length (FStar.Ghost.reveal s) == FStar.Ghost.reveal r - FStar.Ghost.reveal l /\ res == FStar.Seq.Base.index (FStar.Ghost.reveal s) (FStar.SizeT.v i - FStar.Ghost.reveal l)))
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.pts_to_range_index'" ]
[]
false
false
false
false
false
let pts_to_range_index =
pts_to_range_index'
false
FStar.Tactics.MApply.fst
FStar.Tactics.MApply.mapply
val mapply (#ty: Type) {| _: termable ty |} (x: ty) : Tac unit
val mapply (#ty: Type) {| _: termable ty |} (x: ty) : Tac unit
let mapply (#ty:Type) {| termable ty |} (x : ty) : Tac unit = let t = to_term x in apply_squash_or_lem 10 t
{ "file_name": "ulib/FStar.Tactics.MApply.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 111, "start_col": 0, "start_line": 109 }
module FStar.Tactics.MApply open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxHelpers open FStar.Tactics.V2.Derived open FStar.Tactics.V2.SyntaxCoercions open FStar.Tactics.Typeclasses private val push1 : (#p:Type) -> (#q:Type) -> squash (p ==> q) -> squash p -> squash q private let push1 #p #q f u = () private val push1' : (#p:Type) -> (#q:Type) -> (p ==> q) -> squash p -> squash q private let push1' #p #q f u = () (* * Some easier applying, which should prevent frustration * (or cause more when it doesn't do what you wanted to) *) val apply_squash_or_lem : d:nat -> term -> Tac unit let rec apply_squash_or_lem d t = (* Before anything, try a vanilla apply and apply_lemma *) try apply t with | _ -> try apply (`FStar.Squash.return_squash); apply t with | _ -> try apply_lemma t with | _ -> // Fuel cutoff, just in case. if d <= 0 then fail "mapply: out of fuel" else begin let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> begin let post = `((`#post) ()) in (* unthunk *) let post = norm_term [] post in (* Is the lemma an implication? We can try to intro *) match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end | C_Total rt -> begin match unsquash_term rt with (* If the function returns a squash, just apply it, since our goals are squashed *) | Some rt -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end (* If not, we can try to introduce the squash ourselves first *) | None -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> apply (`FStar.Squash.return_squash); apply t end end | _ -> fail "mapply: can't apply (2)" end class termable (a : Type) = { to_term : a -> Tac term } instance termable_term : termable term = { to_term = (fun t -> t); } instance termable_binding : termable binding = { to_term = (fun b -> binding_to_term b); } (* `m` is for `magic` *) let mapply0 (t : term) : Tac unit = apply_squash_or_lem 10 t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Tactics.MApply.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.Derived", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "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
{| _: FStar.Tactics.MApply.termable ty |} -> x: ty -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.MApply.termable", "FStar.Tactics.MApply.apply_squash_or_lem", "Prims.unit", "FStar.Tactics.NamedView.term", "FStar.Tactics.MApply.to_term" ]
[]
false
true
false
false
false
let mapply (#ty: Type) {| _: termable ty |} (x: ty) : Tac unit =
let t = to_term x in apply_squash_or_lem 10 t
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.pts_to_range_upd
val pts_to_range_upd (#t: Type) (a: array t) (i: SZ.t) (v: t) (#l: Ghost.erased nat{l <= SZ.v i}) (#r: Ghost.erased nat{SZ.v i < r}) (#s0: Ghost.erased (Seq.seq t)) : stt unit (requires pts_to_range a l r s0) (ensures fun _ -> exists* s. pts_to_range a l r s ** pure( Seq.length s0 == r - l /\ s == Seq.upd s0 (SZ.v i - l) v ))
val pts_to_range_upd (#t: Type) (a: array t) (i: SZ.t) (v: t) (#l: Ghost.erased nat{l <= SZ.v i}) (#r: Ghost.erased nat{SZ.v i < r}) (#s0: Ghost.erased (Seq.seq t)) : stt unit (requires pts_to_range a l r s0) (ensures fun _ -> exists* s. pts_to_range a l r s ** pure( Seq.length s0 == r - l /\ s == Seq.upd s0 (SZ.v i - l) v ))
let pts_to_range_upd = pts_to_range_upd'
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 40, "end_line": 875, "start_col": 0, "start_line": 875 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i) let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s) ```pulse ghost fn elim_in_bounds (#elt:Type) (#i #j:nat) (s:array elt) (p:in_bounds i j s) requires emp ensures pure (i <= j /\ j <= length s) { () } ``` let token (x:'a) = emp let pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop = exists* (q:in_bounds i j x). pts_to (array_slice x i j) #p s ** token q ```pulse ghost fn pts_to_range_prop' (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ensures pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ Seq.length s == j - i) ) { unfold pts_to_range a i j #p s; with q. assert (token #(in_bounds i j a) q); elim_in_bounds a q; pts_to_len (array_slice a i j); fold pts_to_range a i j #p s; } ``` let pts_to_range_prop = pts_to_range_prop' ```pulse ghost fn pts_to_range_intro' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to a #p s ensures pts_to_range a 0 (length a) #p s { rewrite each a as (array_slice a 0 (length a)); let q : in_bounds 0 (length a) a = (); fold (token #(in_bounds 0 (length a) a) q); fold (pts_to_range a 0 (length a) #p s); } ``` let pts_to_range_intro = pts_to_range_intro' ```pulse ghost fn pts_to_range_elim' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to_range a 0 (length a) #p s ensures pts_to a #p s { unfold (pts_to_range a 0 (length a) #p s); unfold (token #(in_bounds 0 (length a) a) _); rewrite each (array_slice a 0 (length a)) as a; } ``` let pts_to_range_elim = pts_to_range_elim' let mk_carrier_split (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: perm) (i: nat) (_:squash ( offset + Seq.length s <= len /\ i <= Seq.length s )) : squash ( let c1 = mk_carrier len offset (Seq.slice s 0 i) p in let c2 = mk_carrier len (offset + i) (Seq.slice s i (Seq.length s)) p in composable c1 c2 /\ mk_carrier len offset s p `Map.equal` (c1 `compose` c2) ) = () ```pulse ghost fn use_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn ghost_split (#elt: Type) (#x: Seq.seq elt) (#p: perm) (a: array elt) (i: nat {i <= length a}) requires pts_to a #p x returns _: squash (i <= length a /\ i <= Seq.length x) ensures pts_to (split_r a i) #p (Seq.slice x i (Seq.length x)) ** pts_to (split_l a i) #p (Seq.slice x 0 i) ** pure (x `Seq.equal` Seq.append (Seq.slice x 0 i) (Seq.slice x i (Seq.length x))) { unfold (pts_to a #p x); use_squash (mk_carrier_split (SZ.v (ptr_of a).base_len) (ptr_of a).offset x p i ()); let xl = Seq.slice x 0 i; let xr = Seq.slice x i (Seq.length x); let vl = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) xl p; let vr = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset + i) xr p; Pulse.Lib.Core.share (ptr_of a).base vl vr; rewrite pcm_pts_to (ptr_of a).base vl as pcm_pts_to (ptr_of (split_l a i)).base vl; rewrite pcm_pts_to (ptr_of a).base vr as pcm_pts_to (ptr_of (split_r a i)).base vr; fold (pts_to (split_l a i) #p xl); fold (pts_to (split_r a i) #p xr); } ``` let vprop_equiv_refl_eq (v0 v1:vprop) (_:squash (v0 == v1)) : vprop_equiv v0 v1 = vprop_equiv_refl v0 let equiv () : FStar.Tactics.Tac unit = let open FStar.Tactics in mapply (`vprop_equiv_refl_eq); smt() ```pulse ghost fn split_l_slice #elt (a : array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_l (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a i m) #p s { rewrite each (split_l (array_slice a i j) (m - i)) as (array_slice a i m); } ``` ```pulse ghost fn split_r_slice #elt (a:array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_r (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a m j) #p s { rewrite each (split_r (array_slice a i j) (m - i)) as (array_slice a m j); } ``` ```pulse ghost fn pts_to_range_split' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ** pure (i <= m /\ m <= j) ensures exists* s1 s2. pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ** pure ( i <= m /\ m <= j /\ j <= length a /\ eq2 #int (Seq.length s) (j - i) /\ s1 == Seq.slice s 0 (m - i) /\ s2 == Seq.slice s (m - i) (Seq.length s) /\ s == Seq.append s1 s2 ) { pts_to_range_prop a; unfold pts_to_range a i j #p s; unfold (token #(in_bounds i j a) _); ghost_split (array_slice a i j) (m - i); split_r_slice a i m j #(Seq.slice s (m - i) (Seq.length s)) (); split_l_slice a i m j (); let q1 : in_bounds i m a = (); let q2 : in_bounds m j a = (); fold (token #(in_bounds i m a) q1); fold (token #(in_bounds m j a) q2); fold (pts_to_range a i m #p (Seq.slice s 0 (m - i))); fold (pts_to_range a m j #p (Seq.slice s (m - i) (Seq.length s))); assert pure (s `Seq.equal` Seq.append (Seq.slice s 0 (m - i)) (Seq.slice s (m - i) (Seq.length s))); } ``` let pts_to_range_split = pts_to_range_split' let mk_carrier_merge (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p: perm) (_:squash ( offset + Seq.length s1 + Seq.length s2 <= len )) : squash ( let c1 = mk_carrier len offset s1 p in let c2 = mk_carrier len (offset + Seq.length s1) s2 p in composable c1 c2 /\ mk_carrier len offset (s1 `Seq.append` s2) p `Map.equal` (c1 `compose` c2) ) = () let adjacent (#elt: Type) (a1 a2: array elt) : Tot prop = base (ptr_of a1) == base (ptr_of a2) /\ offset (ptr_of a1) + (length a1) == offset (ptr_of a2) let merge' (#elt: Type) (a1: array elt) (a2:array elt { adjacent a1 a2 }) = { p = ptr_of a1; length=Ghost.hide (length a1 + length a2) } irreducible let merge #elt a1 a2 : i:array elt{ i == merge' a1 a2 } = merge' a1 a2 ```pulse ghost fn ghost_join (#elt: Type) (#x1 #x2: Seq.seq elt) (#p: perm) (a1 a2: array elt) (h: squash (adjacent a1 a2)) requires pts_to a1 #p x1 ** pts_to a2 #p x2 ensures pts_to (merge a1 a2) #p (x1 `Seq.append` x2) { unfold pts_to a1 #p x1; unfold pts_to a2 #p x2; use_squash (mk_carrier_merge (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 x2 p ()); with w. rewrite pcm_pts_to (ptr_of a2).base w as pcm_pts_to (ptr_of a1).base (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 p); Pulse.Lib.Core.gather (ptr_of a1).base (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 (p)) (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 (p)); with w. rewrite pcm_pts_to (ptr_of a1).base w as pcm_pts_to (ptr_of (merge a1 a2)).base (mk_carrier (SZ.v (ptr_of (merge a1 a2)).base_len) ((ptr_of (merge a1 a2)).offset) (x1 `Seq.append` x2) (p)); fold (pts_to (merge a1 a2) #p (Seq.append x1 x2)); } ``` ```pulse ghost fn pts_to_range_intro_ij (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) (i j: nat) (_:squash (i <= j /\ j <= length a)) requires pts_to (array_slice a i j) #p s ensures pts_to_range a i j #p s { let q : in_bounds i j a = (); fold (token #(in_bounds i j a) q); fold (pts_to_range a i j #p s); } ``` ```pulse ghost fn pts_to_range_join' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s1 #s2: Seq.seq elt) requires pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ensures pts_to_range a i j #p (s1 `Seq.append` s2) { pts_to_range_prop a #i #m; pts_to_range_prop a #m #j; unfold pts_to_range a i m #p s1; unfold pts_to_range a m j #p s2; ghost_join (array_slice a i m) (array_slice a m j) (); rewrite each (merge (array_slice a i m) (array_slice a m j)) as (array_slice a i j); pts_to_range_intro_ij a _ _ i j (); unfold (token #(in_bounds i m a) _); unfold (token #(in_bounds m j a) _); } ``` let pts_to_range_join = pts_to_range_join' irreducible let array_slice_impl (#elt: Type) (a: array elt) (i: SZ.t) (j: Ghost.erased nat) (sq: squash (SZ.v i <= j /\ j <= length a)) : x:array elt { x == array_slice a (SZ.v i) j } = split_l (split_r a (SZ.v i)) (Ghost.hide (j - SZ.v i)) ```pulse fn pts_to_range_index' (#t: Type) (a: array t) (i: SZ.t) (#l: Ghost.erased nat{l <= SZ.v i}) (#r: Ghost.erased nat{SZ.v i < r}) (#s: Ghost.erased (Seq.seq t)) (#p: perm) requires pts_to_range a l r #p s returns res:t ensures pts_to_range a l r #p s ** pure (eq2 #int (Seq.length s) (r - l) /\ res == Seq.index s (SZ.v i - l)) { pts_to_range_split a l (SZ.v i) r; with s1 s2. _; unfold pts_to_range a (SZ.v i) r #p s2; unfold (token #(in_bounds (SZ.v i) r a) _); let a' = array_slice_impl a i r (); rewrite each (array_slice a (SZ.v i) r) as a'; let res = read a' 0sz; rewrite each a' as (array_slice a (SZ.v i) r); pts_to_range_intro_ij a _ _ (SZ.v i) r (); pts_to_range_join a l (SZ.v i) r; res } ``` let pts_to_range_index = pts_to_range_index' ```pulse fn pts_to_range_upd' (#t: Type) (a: array t) (i: SZ.t) (v: t) (#l: Ghost.erased nat{l <= SZ.v i}) (#r: Ghost.erased nat{SZ.v i < r}) (#s0: Ghost.erased (Seq.seq t)) requires pts_to_range a l r #full_perm s0 ensures exists* s. pts_to_range a l r s ** pure ( eq2 #int (Seq.length s0) (r - l) /\ s == Seq.upd s0 (SZ.v i - l) v ) { pts_to_range_split a l (SZ.v i) r; with s1 s2. _; unfold pts_to_range a (SZ.v i) r #full_perm s2; unfold (token #(in_bounds (SZ.v i) r a) _); let a' = array_slice_impl a i r (); rewrite each (array_slice a (SZ.v i) r) as a'; write a' 0sz v; rewrite each a' as (array_slice a (SZ.v i) r); pts_to_range_intro_ij a _ _ (SZ.v i) r (); pts_to_range_join a l (SZ.v i) r; with w. assert (pts_to_range a l r w); assert pure (w `Seq.equal` Seq.upd s0 (SZ.v i - l) v); }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array t -> i: FStar.SizeT.t -> v: t -> Pulse.Lib.Core.stt Prims.unit (Pulse.Lib.HigherArray.pts_to_range a (FStar.Ghost.reveal l) (FStar.Ghost.reveal r) (FStar.Ghost.reveal s0)) (fun _ -> exists* (s: FStar.Seq.Base.seq t). Pulse.Lib.HigherArray.pts_to_range a (FStar.Ghost.reveal l) (FStar.Ghost.reveal r) s ** Pulse.Lib.Core.pure (FStar.Seq.Base.length (FStar.Ghost.reveal s0) == FStar.Ghost.reveal r - FStar.Ghost.reveal l /\ s == FStar.Seq.Base.upd (FStar.Ghost.reveal s0) (FStar.SizeT.v i - FStar.Ghost.reveal l) v))
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.pts_to_range_upd'" ]
[]
false
false
false
false
false
let pts_to_range_upd =
pts_to_range_upd'
false
LowParse.Spec.VCList.fst
LowParse.Spec.VCList.parse_nlist
val parse_nlist (n: nat) (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (y: parser (parse_nlist_kind n k) (nlist n t) { y == parse_nlist' n p } )
val parse_nlist (n: nat) (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (y: parser (parse_nlist_kind n k) (nlist n t) { y == parse_nlist' n p } )
let parse_nlist (n: nat) (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (y: parser (parse_nlist_kind n k) (nlist n t) { y == parse_nlist' n p } ) = parse_nlist' n p
{ "file_name": "src/lowparse/LowParse.Spec.VCList.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 18, "end_line": 18, "start_col": 0, "start_line": 12 }
(* Variable-count lists *) module LowParse.Spec.VCList include LowParse.Spec.Combinators // for seq_slice_append_l include LowParse.Spec.Array // for vlarray module Seq = FStar.Seq module U32 = FStar.UInt32 module Classical = FStar.Classical module L = FStar.List.Tot
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Array.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.VCList.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Classical", "short_module": "Classical" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Array", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Classical", "short_module": "Classical" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Array", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> p: LowParse.Spec.Base.parser k t -> y: LowParse.Spec.Base.parser (LowParse.Spec.VCList.parse_nlist_kind n k) (LowParse.Spec.VCList.nlist n t) {y == LowParse.Spec.VCList.parse_nlist' n p}
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.VCList.parse_nlist'", "LowParse.Spec.VCList.parse_nlist_kind", "LowParse.Spec.VCList.nlist", "Prims.eq2" ]
[]
false
false
false
false
false
let parse_nlist (n: nat) (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (y: parser (parse_nlist_kind n k) (nlist n t) {y == parse_nlist' n p}) =
parse_nlist' n p
false
Hacl.Bignum.Montgomery.fsti
Hacl.Bignum.Montgomery.bn_of_mont
[@@ FStar.Tactics.Typeclasses.tcinstance] val bn_of_mont (t: limb_t) (x: mont t) : BN.bn t
[@@ FStar.Tactics.Typeclasses.tcinstance] val bn_of_mont (t: limb_t) (x: mont t) : BN.bn t
instance bn_of_mont (t:limb_t) (x:mont t) : BN.bn t = x.bn
{ "file_name": "code/bignum/Hacl.Bignum.Montgomery.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 184, "start_col": 0, "start_line": 184 }
module Hacl.Bignum.Montgomery open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Bignum include Hacl.Bignum.ModInvLimb #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n)) inline_for_extraction noextract val bn_check_modulus: #t:limb_t -> #len:BN.meta_len t -> bn_check_modulus_st t len inline_for_extraction noextract let bn_precomp_r2_mod_n_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t{v nBits / bits t < v len} -> n:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h res /\ disjoint n res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_precomp_r2_mod_n (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_precomp_r2_mod_n: #t:limb_t -> k:BN.bn t -> bn_precomp_r2_mod_n_st t k.BN.len inline_for_extraction noextract let bn_mont_precomp_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t -> n:lbignum t len -> r2:lbignum t len -> Stack (limb t) (requires fun h -> live h n /\ live h r2 /\ disjoint n r2 /\ 1 < bn_v h n /\ bn_v h n % 2 = 1 /\ pow2 (v nBits) < bn_v h n /\ v nBits / bits t < v len) (ensures fun h0 mu h1 -> modifies (loc r2) h0 h1 /\ (as_seq h1 r2, mu) == S.bn_mont_precomp (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_mont_precomp: #t:limb_t -> len:BN.meta_len t -> precompr2:bn_precomp_r2_mod_n_st t len -> bn_mont_precomp_st t len inline_for_extraction noextract let bn_mont_reduction_st (t:limb_t) (len:size_t{0 < v len /\ v len + v len <= max_size_t}) = n:lbignum t len -> mu:limb t -> c:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h c /\ live h res /\ disjoint res n /\ disjoint res c /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc res |+| loc c) h0 h1 /\ as_seq h1 res == S.bn_mont_reduction (as_seq h0 n) mu (as_seq h0 c)) inline_for_extraction noextract val bn_mont_reduction: #t:limb_t -> k:BN.bn t -> bn_mont_reduction_st t k.BN.len inline_for_extraction noextract let bn_to_mont_st (t:limb_t) (nLen:BN.meta_len t) = n:lbignum t nLen -> mu:limb t -> r2:lbignum t nLen -> a:lbignum t nLen -> aM:lbignum t nLen -> Stack unit (requires fun h -> live h n /\ live h r2 /\ live h a /\ live h aM /\ disjoint a r2 /\ disjoint a n /\ disjoint a aM /\ disjoint n r2 /\ disjoint n aM /\ disjoint r2 aM) (ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\ as_seq h1 aM == S.bn_to_mont (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a)) inline_for_extraction noextract val bn_to_mont: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_to_mont_st t k.BN.len inline_for_extraction noextract let bn_from_mont_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> a:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h a /\ live h aM /\ disjoint aM a /\ disjoint aM n /\ disjoint a n) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_seq h1 a == S.bn_from_mont (as_seq h0 n) mu (as_seq h0 aM)) // This one just needs a specialized implementation of mont_reduction. No point // in doing a type class for a single function , so we take it as a parameter. inline_for_extraction noextract val bn_from_mont: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_from_mont_st t k.BN.len inline_for_extraction noextract let bn_mont_mul_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> bM:lbignum t len -> resM:lbignum t len -> Stack unit (requires fun h -> live h aM /\ live h bM /\ live h resM /\ live h n /\ disjoint resM n /\ eq_or_disjoint aM bM /\ eq_or_disjoint aM resM /\ eq_or_disjoint bM resM) (ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\ as_seq h1 resM == S.bn_mont_mul (as_seq h0 n) mu (as_seq h0 aM) (as_seq h0 bM)) /// This one needs both the type class and a specialized montgomery reduction. inline_for_extraction noextract val bn_mont_mul: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_mont_mul_st t k.BN.len inline_for_extraction noextract let bn_mont_sqr_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> resM:lbignum t len -> Stack unit (requires fun h -> live h aM /\ live h resM /\ live h n /\ disjoint resM n /\ eq_or_disjoint aM resM) (ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\ as_seq h1 resM == S.bn_mont_sqr (as_seq h0 n) mu (as_seq h0 aM)) /// This one needs both the type class and a specialized montgomery reduction. inline_for_extraction noextract val bn_mont_sqr: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_mont_sqr_st t k.BN.len inline_for_extraction noextract class mont (t:limb_t) = { bn: BN.bn t; mont_check: bn_check_modulus_st t bn.BN.len; precomp: bn_precomp_r2_mod_n_st t bn.BN.len; reduction: bn_mont_reduction_st t bn.BN.len; to: bn_to_mont_st t bn.BN.len; from: bn_from_mont_st t bn.BN.len; mul: bn_mont_mul_st t bn.BN.len; sqr: bn_mont_sqr_st t bn.BN.len; } /// Encoding type-class hierarchies via a hook for type class resolution.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModInvLimb.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Montgomery.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Bignum.ModInvLimb", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> x: Hacl.Bignum.Montgomery.mont t -> Hacl.Bignum.bn t
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.Montgomery.mont", "Hacl.Bignum.Montgomery.__proj__Mkmont__item__bn", "Hacl.Bignum.bn" ]
[]
false
false
false
false
false
[@@ FStar.Tactics.Typeclasses.tcinstance] let bn_of_mont (t: limb_t) (x: mont t) : BN.bn t =
x.bn
false
Pulse.Lib.HigherArray.fst
Pulse.Lib.HigherArray.array_slice_impl
val array_slice_impl (#elt: Type) (a: array elt) (i: SZ.t) (j: Ghost.erased nat) (sq: squash (SZ.v i <= j /\ j <= length a)) : x: array elt {x == array_slice a (SZ.v i) j}
val array_slice_impl (#elt: Type) (a: array elt) (i: SZ.t) (j: Ghost.erased nat) (sq: squash (SZ.v i <= j /\ j <= length a)) : x: array elt {x == array_slice a (SZ.v i) j}
let array_slice_impl (#elt: Type) (a: array elt) (i: SZ.t) (j: Ghost.erased nat) (sq: squash (SZ.v i <= j /\ j <= length a)) : x:array elt { x == array_slice a (SZ.v i) j } = split_l (split_r a (SZ.v i)) (Ghost.hide (j - SZ.v i))
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 56, "end_line": 810, "start_col": 0, "start_line": 803 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HigherArray open Pulse.Main open FStar.Tactics.V2 open Pulse.Lib.Core open PulseCore.FractionalPermission open FStar.Ghost module SZ = FStar.SizeT module Seq = FStar.Seq open FStar.PCM module Frac = Pulse.Lib.PCM.Fraction module PM = Pulse.Lib.PCM.Map open Pulse.Lib.PCM.Array module PA = Pulse.Lib.PCM.Array /// An abstract type to represent a base array (whole allocation /// unit), exposed for proof purposes only [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: SZ.t & pcm_ref (PA.pcm elt (SZ.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = SZ.v (dfst b) /// An abstract type to represent a C pointer, as a base and an offset /// into its base let l_pcm_ref (elt:Type u#a) (base_len:SZ.t) = r:pcm_ref (PA.pcm elt (SZ.v base_len)){ is_pcm_ref_null r = false || base_len = 0sz } noeq type ptr ([@@@strictly_positive]elt: Type u#a) : Type0 = { base_len: Ghost.erased SZ.t; base: l_pcm_ref elt base_len; offset: (offset: nat { offset <= SZ.v base_len }); } let null_ptr (a:Type u#a) : ptr a = { base_len = 0sz; base = pcm_ref_null (PA.pcm a 0) ; offset = 0 } let is_null_ptr (#elt: Type u#a) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt)) = is_pcm_ref_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr (elt: Type u#a) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))] = () noeq type array ([@@@strictly_positive] elt: Type u#1) : Type0 = { p: ptr elt; length: (l:Ghost.erased nat {offset p + l <= base_len (base p)}) } let length (#elt: Type) (a: array elt) : GTot nat = a.length let ptr_of (#elt: Type) (a: array elt) : Tot (ptr elt) = a.p let is_full_array (#elt: Type) (a: array elt) : Tot prop = length a == base_len (base (ptr_of a)) let null (#a: Type u#1) : array a = { p = null_ptr a; length =Ghost.hide 0 } let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: perm) : prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.v <=. one)) let pts_to (#elt: Type u#1) (a: array elt) (#p: perm) (s: Seq.seq elt) : Tot vprop = pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p) ** pure ( valid_perm (SZ.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let mk_array (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) : array elt = { p = { base_len; base; offset} ; length = Ghost.hide (SZ.v base_len - offset) } ```pulse ghost fn fold_pts_to (#elt: Type u#1) (base_len: SZ.t) (base:l_pcm_ref elt base_len) (offset:nat { offset <= SZ.v base_len}) (#p: perm { p `lesser_equal_perm` full_perm}) (s: Seq.seq elt { Seq.length s == SZ.v base_len - offset}) requires pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p) ensures pts_to (mk_array base_len base offset) #p s { let a = (mk_array base_len base offset); rewrite (pcm_pts_to base (mk_carrier (SZ.v base_len) offset s p)) as pcm_pts_to (ptr_of a).base (mk_carrier (SZ.v (ptr_of a).base_len) (ptr_of a).offset s p); fold (pts_to a #p s); rewrite (pts_to a #p s) as (pts_to (mk_array base_len base offset) #p s); } ``` ```pulse ghost fn pts_to_len' (#elt: Type u#1) (a:array elt) (#p:perm) (#x:Seq.seq elt) requires pts_to a #p x ensures pts_to a #p x ** pure (length a == Seq.length x) { unfold pts_to a #p x; fold pts_to a #p x; } ``` let pts_to_len = pts_to_len' ```pulse fn alloc' (#elt: Type u#1) (x: elt) (n: SZ.t) requires emp returns a:array elt ensures pts_to a (Seq.create (SZ.v n) x) ** pure (length a == SZ.v n /\ is_full_array a) { let v = (mk_carrier (SZ.v n) 0 (Seq.create (SZ.v n) x) full_perm); FStar.PCM.compatible_refl (PA.pcm elt (SZ.v n)) v; let b = Pulse.Lib.Core.alloc #_ #(PA.pcm elt (SZ.v n)) v; pts_to_not_null b _; fold_pts_to n b 0 #full_perm (Seq.create (SZ.v n) x); mk_array n b 0; } ``` let alloc = alloc' ```pulse fn read (#t: Type) (a: array t) (i: SZ.t) (#p: perm) (#s: Ghost.erased (Seq.seq t){SZ.v i < Seq.length s}) requires pts_to a #p s returns res:t ensures pts_to a #p s ** pure (res == Seq.index s (SZ.v i)) { unfold pts_to a #p s; with w. assert (pcm_pts_to (ptr_of a).base w); let v = Pulse.Lib.Core.read (ptr_of a).base w (fun _ -> w); fold (pts_to a #p s); fst (Some?.v (FStar.Map.sel v ((ptr_of a).offset + SZ.v i))); } ``` let op_Array_Access = read let mk_carrier_upd (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (i: nat) (v: elt) (_: squash ( offset + Seq.length s <= len /\ i < Seq.length s )) : Lemma (ensures ( let o = mk_carrier len offset s full_perm in let o' = mk_carrier len offset (Seq.upd s i v) full_perm in o' `Map.equal` Map.upd o (offset + i) (Some (v, full_perm)) )) = () ```pulse fn write (#t: Type) (a: array t) (i: SZ.t) (v: t) (#s: Ghost.erased (Seq.seq t) {SZ.v i < Seq.length s}) requires pts_to a s ensures pts_to a (Seq.upd s (SZ.v i) v) { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); mk_carrier_upd (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) s (SZ.v i) v (); Pulse.Lib.Core.write (ptr_of a).base w _ (PM.lift_frame_preserving_upd _ _ (Frac.mk_frame_preserving_upd (Seq.index s (SZ.v i)) v ) _ ((ptr_of a).offset + SZ.v i)); fold (pts_to a #full_perm (Seq.upd s (SZ.v i) v)); } ``` let op_Array_Assignment = write (* let frame_preserving_upd_one (#elt:Type) (n:erased nat) (s:erased (Seq.seq elt) { Seq.length s == reveal n }) : FStar.PCM.frame_preserving_upd (PA.pcm elt n) (mk_carrier n 0 s full_perm) (PA.one #elt #n) = fun _ -> admit(); (PA.one #elt #n) *) ```pulse fn free' (#elt: Type) (a: array elt) (#s: Ghost.erased (Seq.seq elt)) requires pts_to a s ** pure (is_full_array a) ensures emp { unfold pts_to a #full_perm s; with w. assert (pcm_pts_to (ptr_of a).base w); // Pulse.Lib.Core.write (ptr_of a).base w (PA.one #elt #(length a)) (frame_preserving_upd_one #elt (length a) s); drop_ (pcm_pts_to (ptr_of a).base _) } ``` let free = free' let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (sum_perm p1 p2) ```pulse ghost fn mk_carrier_share (#elt: Type u#1) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) (_:squash (valid_sum_perm len offset (Seq.length s) p1 p2)) requires emp ensures ( // let c1 = (mk_carrier len offset s p1) in pure ( composable (mk_carrier len offset s p1) (mk_carrier len offset s p2) /\ mk_carrier len offset s (p1 `sum_perm` p2) `Map.equal` ((mk_carrier len offset s p1) `compose` (mk_carrier len offset s p2)) ) ) { () } ``` ```pulse ghost fn share' (#elt:Type) (arr:array elt) (#s:Ghost.erased (Seq.seq elt)) (#p:perm) requires pts_to arr #p s ensures pts_to arr #(half_perm p) s ** pts_to arr #(half_perm p) s { unfold pts_to arr #p s; with w. assert (pcm_pts_to (ptr_of arr).base w); mk_carrier_share (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p) (half_perm p) (); Pulse.Lib.Core.share (ptr_of arr).base (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)) (mk_carrier (SZ.v (ptr_of arr).base_len) (ptr_of arr).offset s (half_perm p)); fold pts_to arr #(half_perm p) s; fold pts_to arr #(half_perm p) s; } ``` let share = share' let mk_carrier_gather (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm) (_:squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ Seq.length s1 == Seq.length s2 /\ offset + Seq.length s1 <= len )) : squash ( let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in composable c1 c2 /\ mk_carrier len offset s1 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ mk_carrier len offset s2 (p1 `sum_perm` p2) == (c1 `compose` c2) /\ s1 == s2 ) = let c1 = mk_carrier len offset s1 p1 in let c2 = mk_carrier len offset s2 p2 in assert (composable c1 c2); assert (mk_carrier len offset s1 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); assert (mk_carrier len offset s2 (p1 `sum_perm` p2) `Map.equal` (c1 `compose` c2)); mk_carrier_inj len offset s1 s2 (p1 `sum_perm` p2) (p1 `sum_perm` p2) let mk_carrier_valid_sum_perm (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: perm) : squash (let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2) = let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in if Seq.length s > 0 && offset + Seq.length s <= len then let open FStar.Real in assert (Frac.composable (Map.sel c1 offset) (Map.sel c2 offset) <==> valid_perm len offset (Seq.length s) (sum_perm p1 p2)) else () ```pulse ghost fn of_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn gather' (#a:Type) (arr:array a) (#s0 #s1:Ghost.erased (Seq.seq a)) (#p0 #p1:perm) requires pts_to arr #p0 s0 ** pts_to arr #p1 s1 ensures pts_to arr #(sum_perm p0 p1) s0 ** pure (s0 == s1) { unfold pts_to arr #p0 s0; with w0. assert (pcm_pts_to (ptr_of arr).base w0); unfold pts_to arr #p1 s1; with w1. assert (pcm_pts_to (ptr_of arr).base w1); Pulse.Lib.Core.gather (ptr_of arr).base w0 w1; of_squash (mk_carrier_gather (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 s1 p0 p1 ()); of_squash (mk_carrier_valid_sum_perm (SZ.v (ptr_of arr).base_len) ((ptr_of arr).offset) s0 p0 p1); fold pts_to arr #(sum_perm p0 p1) s0; } ``` let gather = gather' let ptr_shift (#elt: Type) (p: ptr elt) (off: nat {offset p + off <= base_len (base p)}) : ptr elt = { base_len = p.base_len; base = p.base; offset = p.offset + off; } let split_l' (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : array elt = { p = ptr_of a; length=i } irreducible let split_l (#elt: Type) (a: array elt) (i: erased nat {i <= length a}) : x:array elt { x == split_l' a i } = split_l' a i let split_r' (#elt: Type) (a: array elt) (i: nat {i <= length a}) : array elt = { p= ptr_shift (ptr_of a) i; length=Ghost.hide (length a - i) } irreducible let split_r (#elt: Type) (a: array elt) (i: nat {i <= length a}) : x:array elt { x == split_r' a i } = split_r' a i let array_slice (#elt: Type) (a: array elt) (i:nat) (j: nat {i <= j /\ j <= length a}) : GTot (array elt) = split_l (split_r a i) (j - i) let in_bounds (i j:nat) (s:array 'a) = squash (i <= j /\ j <= length s) ```pulse ghost fn elim_in_bounds (#elt:Type) (#i #j:nat) (s:array elt) (p:in_bounds i j s) requires emp ensures pure (i <= j /\ j <= length s) { () } ``` let token (x:'a) = emp let pts_to_range (#a:Type) (x:array a) ([@@@ equate_by_smt] i:nat) ([@@@ equate_by_smt] j: nat) (#[exact (`full_perm)] p:perm) ([@@@ equate_by_smt] s: Seq.seq a) : vprop = exists* (q:in_bounds i j x). pts_to (array_slice x i j) #p s ** token q ```pulse ghost fn pts_to_range_prop' (#elt: Type) (a: array elt) (#i #j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ensures pts_to_range a i j #p s ** pure ( (i <= j /\ j <= length a /\ Seq.length s == j - i) ) { unfold pts_to_range a i j #p s; with q. assert (token #(in_bounds i j a) q); elim_in_bounds a q; pts_to_len (array_slice a i j); fold pts_to_range a i j #p s; } ``` let pts_to_range_prop = pts_to_range_prop' ```pulse ghost fn pts_to_range_intro' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to a #p s ensures pts_to_range a 0 (length a) #p s { rewrite each a as (array_slice a 0 (length a)); let q : in_bounds 0 (length a) a = (); fold (token #(in_bounds 0 (length a) a) q); fold (pts_to_range a 0 (length a) #p s); } ``` let pts_to_range_intro = pts_to_range_intro' ```pulse ghost fn pts_to_range_elim' (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) requires pts_to_range a 0 (length a) #p s ensures pts_to a #p s { unfold (pts_to_range a 0 (length a) #p s); unfold (token #(in_bounds 0 (length a) a) _); rewrite each (array_slice a 0 (length a)) as a; } ``` let pts_to_range_elim = pts_to_range_elim' let mk_carrier_split (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: perm) (i: nat) (_:squash ( offset + Seq.length s <= len /\ i <= Seq.length s )) : squash ( let c1 = mk_carrier len offset (Seq.slice s 0 i) p in let c2 = mk_carrier len (offset + i) (Seq.slice s i (Seq.length s)) p in composable c1 c2 /\ mk_carrier len offset s p `Map.equal` (c1 `compose` c2) ) = () ```pulse ghost fn use_squash (#p:prop) (s:squash p) requires emp ensures pure p { () } ``` ```pulse ghost fn ghost_split (#elt: Type) (#x: Seq.seq elt) (#p: perm) (a: array elt) (i: nat {i <= length a}) requires pts_to a #p x returns _: squash (i <= length a /\ i <= Seq.length x) ensures pts_to (split_r a i) #p (Seq.slice x i (Seq.length x)) ** pts_to (split_l a i) #p (Seq.slice x 0 i) ** pure (x `Seq.equal` Seq.append (Seq.slice x 0 i) (Seq.slice x i (Seq.length x))) { unfold (pts_to a #p x); use_squash (mk_carrier_split (SZ.v (ptr_of a).base_len) (ptr_of a).offset x p i ()); let xl = Seq.slice x 0 i; let xr = Seq.slice x i (Seq.length x); let vl = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset) xl p; let vr = mk_carrier (SZ.v (ptr_of a).base_len) ((ptr_of a).offset + i) xr p; Pulse.Lib.Core.share (ptr_of a).base vl vr; rewrite pcm_pts_to (ptr_of a).base vl as pcm_pts_to (ptr_of (split_l a i)).base vl; rewrite pcm_pts_to (ptr_of a).base vr as pcm_pts_to (ptr_of (split_r a i)).base vr; fold (pts_to (split_l a i) #p xl); fold (pts_to (split_r a i) #p xr); } ``` let vprop_equiv_refl_eq (v0 v1:vprop) (_:squash (v0 == v1)) : vprop_equiv v0 v1 = vprop_equiv_refl v0 let equiv () : FStar.Tactics.Tac unit = let open FStar.Tactics in mapply (`vprop_equiv_refl_eq); smt() ```pulse ghost fn split_l_slice #elt (a : array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_l (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a i m) #p s { rewrite each (split_l (array_slice a i j) (m - i)) as (array_slice a i m); } ``` ```pulse ghost fn split_r_slice #elt (a:array elt) (i m j: nat) (#s:Seq.seq elt) (_:squash (i <= m /\ m <= j /\ j <= length a)) requires pts_to (split_r (array_slice a i j) (m - i)) #p s ensures pts_to (array_slice a m j) #p s { rewrite each (split_r (array_slice a i j) (m - i)) as (array_slice a m j); } ``` ```pulse ghost fn pts_to_range_split' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s: Seq.seq elt) requires pts_to_range a i j #p s ** pure (i <= m /\ m <= j) ensures exists* s1 s2. pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ** pure ( i <= m /\ m <= j /\ j <= length a /\ eq2 #int (Seq.length s) (j - i) /\ s1 == Seq.slice s 0 (m - i) /\ s2 == Seq.slice s (m - i) (Seq.length s) /\ s == Seq.append s1 s2 ) { pts_to_range_prop a; unfold pts_to_range a i j #p s; unfold (token #(in_bounds i j a) _); ghost_split (array_slice a i j) (m - i); split_r_slice a i m j #(Seq.slice s (m - i) (Seq.length s)) (); split_l_slice a i m j (); let q1 : in_bounds i m a = (); let q2 : in_bounds m j a = (); fold (token #(in_bounds i m a) q1); fold (token #(in_bounds m j a) q2); fold (pts_to_range a i m #p (Seq.slice s 0 (m - i))); fold (pts_to_range a m j #p (Seq.slice s (m - i) (Seq.length s))); assert pure (s `Seq.equal` Seq.append (Seq.slice s 0 (m - i)) (Seq.slice s (m - i) (Seq.length s))); } ``` let pts_to_range_split = pts_to_range_split' let mk_carrier_merge (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p: perm) (_:squash ( offset + Seq.length s1 + Seq.length s2 <= len )) : squash ( let c1 = mk_carrier len offset s1 p in let c2 = mk_carrier len (offset + Seq.length s1) s2 p in composable c1 c2 /\ mk_carrier len offset (s1 `Seq.append` s2) p `Map.equal` (c1 `compose` c2) ) = () let adjacent (#elt: Type) (a1 a2: array elt) : Tot prop = base (ptr_of a1) == base (ptr_of a2) /\ offset (ptr_of a1) + (length a1) == offset (ptr_of a2) let merge' (#elt: Type) (a1: array elt) (a2:array elt { adjacent a1 a2 }) = { p = ptr_of a1; length=Ghost.hide (length a1 + length a2) } irreducible let merge #elt a1 a2 : i:array elt{ i == merge' a1 a2 } = merge' a1 a2 ```pulse ghost fn ghost_join (#elt: Type) (#x1 #x2: Seq.seq elt) (#p: perm) (a1 a2: array elt) (h: squash (adjacent a1 a2)) requires pts_to a1 #p x1 ** pts_to a2 #p x2 ensures pts_to (merge a1 a2) #p (x1 `Seq.append` x2) { unfold pts_to a1 #p x1; unfold pts_to a2 #p x2; use_squash (mk_carrier_merge (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 x2 p ()); with w. rewrite pcm_pts_to (ptr_of a2).base w as pcm_pts_to (ptr_of a1).base (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 p); Pulse.Lib.Core.gather (ptr_of a1).base (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 (p)) (mk_carrier (SZ.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 (p)); with w. rewrite pcm_pts_to (ptr_of a1).base w as pcm_pts_to (ptr_of (merge a1 a2)).base (mk_carrier (SZ.v (ptr_of (merge a1 a2)).base_len) ((ptr_of (merge a1 a2)).offset) (x1 `Seq.append` x2) (p)); fold (pts_to (merge a1 a2) #p (Seq.append x1 x2)); } ``` ```pulse ghost fn pts_to_range_intro_ij (#elt: Type) (a: array elt) (p: perm) (s: Seq.seq elt) (i j: nat) (_:squash (i <= j /\ j <= length a)) requires pts_to (array_slice a i j) #p s ensures pts_to_range a i j #p s { let q : in_bounds i j a = (); fold (token #(in_bounds i j a) q); fold (pts_to_range a i j #p s); } ``` ```pulse ghost fn pts_to_range_join' (#elt: Type) (a: array elt) (i m j: nat) (#p: perm) (#s1 #s2: Seq.seq elt) requires pts_to_range a i m #p s1 ** pts_to_range a m j #p s2 ensures pts_to_range a i j #p (s1 `Seq.append` s2) { pts_to_range_prop a #i #m; pts_to_range_prop a #m #j; unfold pts_to_range a i m #p s1; unfold pts_to_range a m j #p s2; ghost_join (array_slice a i m) (array_slice a m j) (); rewrite each (merge (array_slice a i m) (array_slice a m j)) as (array_slice a i j); pts_to_range_intro_ij a _ _ i j (); unfold (token #(in_bounds i m a) _); unfold (token #(in_bounds m j a) _); } ``` let pts_to_range_join = pts_to_range_join'
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "Pulse.Main.fsti.checked", "Pulse.Lib.PCM.Map.fst.checked", "Pulse.Lib.PCM.Fraction.fst.checked", "Pulse.Lib.PCM.Array.fst.checked", "Pulse.Lib.Core.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Lib.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.PCM.Array", "short_module": "PA" }, { "abbrev": false, "full_module": "Pulse.Lib.PCM.Array", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Map", "short_module": "PM" }, { "abbrev": true, "full_module": "Pulse.Lib.PCM.Fraction", "short_module": "Frac" }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Main", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Core", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.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": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.Lib.HigherArray.array elt -> i: FStar.SizeT.t -> j: FStar.Ghost.erased Prims.nat -> sq: Prims.squash (FStar.SizeT.v i <= FStar.Ghost.reveal j /\ FStar.Ghost.reveal j <= Pulse.Lib.HigherArray.length a) -> x: Pulse.Lib.HigherArray.array elt {x == Pulse.Lib.HigherArray.array_slice a (FStar.SizeT.v i) (FStar.Ghost.reveal j)}
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.HigherArray.array", "FStar.SizeT.t", "FStar.Ghost.erased", "Prims.nat", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.SizeT.v", "FStar.Ghost.reveal", "Pulse.Lib.HigherArray.length", "Pulse.Lib.HigherArray.split_l", "Pulse.Lib.HigherArray.split_r", "FStar.Ghost.hide", "Prims.op_Subtraction", "Prims.eq2", "Pulse.Lib.HigherArray.array_slice" ]
[]
false
false
false
false
false
let array_slice_impl (#elt: Type) (a: array elt) (i: SZ.t) (j: Ghost.erased nat) (sq: squash (SZ.v i <= j /\ j <= length a)) : x: array elt {x == array_slice a (SZ.v i) j} =
split_l (split_r a (SZ.v i)) (Ghost.hide (j - SZ.v i))
false
LowParse.Spec.VCList.fst
LowParse.Spec.VCList.serialize_nlist
val serialize_nlist (n: nat) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong } ) : Tot (y: serializer (parse_nlist n p) { y == serialize_nlist' n s })
val serialize_nlist (n: nat) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong } ) : Tot (y: serializer (parse_nlist n p) { y == serialize_nlist' n s })
let serialize_nlist (n: nat) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong } ) : Tot (y: serializer (parse_nlist n p) { y == serialize_nlist' n s }) = serialize_nlist' n s
{ "file_name": "src/lowparse/LowParse.Spec.VCList.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 22, "end_line": 27, "start_col": 0, "start_line": 20 }
(* Variable-count lists *) module LowParse.Spec.VCList include LowParse.Spec.Combinators // for seq_slice_append_l include LowParse.Spec.Array // for vlarray module Seq = FStar.Seq module U32 = FStar.UInt32 module Classical = FStar.Classical module L = FStar.List.Tot let parse_nlist (n: nat) (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (y: parser (parse_nlist_kind n k) (nlist n t) { y == parse_nlist' n p } ) = parse_nlist' n p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Array.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.VCList.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Classical", "short_module": "Classical" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Array", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Classical", "short_module": "Classical" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Array", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> s: LowParse.Spec.Base.serializer p { Mkparser_kind'?.parser_kind_subkind k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> y: LowParse.Spec.Base.serializer (LowParse.Spec.VCList.parse_nlist n p) {y == LowParse.Spec.VCList.serialize_nlist' n s}
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Spec.VCList.serialize_nlist'", "LowParse.Spec.VCList.parse_nlist_kind", "LowParse.Spec.VCList.nlist", "LowParse.Spec.VCList.parse_nlist" ]
[]
false
false
false
false
false
let serialize_nlist (n: nat) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) : Tot (y: serializer (parse_nlist n p) {y == serialize_nlist' n s}) =
serialize_nlist' n s
false
Steel.ST.C.Types.Fields.fsti
Steel.ST.C.Types.Fields.field_description_cons0
val field_description_cons0 (fn #ft #fc: Type0) (n: string) (t: typedef ft) (fd: field_description_t fc) : Tot (nonempty_field_description_t (field_t_cons fn ft fc))
val field_description_cons0 (fn #ft #fc: Type0) (n: string) (t: typedef ft) (fd: field_description_t fc) : Tot (nonempty_field_description_t (field_t_cons fn ft fc))
let field_description_cons0 (fn: Type0) (#ft: Type0) (#fc: Type0) (n: string) (t: typedef ft) (fd: field_description_t fc) : Tot (nonempty_field_description_t (field_t_cons fn ft fc)) = { fd_def = (fun n' -> n = n' || fd.fd_def n'); fd_empty = false; fd_type = (fun n' -> if n = n' then ft else fd.fd_type n'); fd_typedef = (fun n' -> if n = n' then t else fd.fd_typedef n'); }
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Fields.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 49, "start_col": 0, "start_line": 41 }
module Steel.ST.C.Types.Fields include Steel.ST.C.Types.Base open Steel.C.Typestring open Steel.ST.Util [@@noextract_to "krml"] // tactic let norm_fields () : FStar.Tactics.Tac unit = FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops]; FStar.Tactics.trefl () [@@noextract_to "krml"] // primitive val field_t_nil: Type0 [@@noextract_to "krml"] // primitive val field_t_cons (fn: Type0) (ft: Type0) (fc: Type0): Type0 inline_for_extraction [@@noextract_to "krml"; norm_field_attr] noeq type field_description_t (t: Type0) : Type u#1 = { fd_def: (string -> GTot bool); fd_empty: (fd_empty: bool { fd_empty == true <==> (forall s . fd_def s == false) }); fd_type: (string -> Type0); fd_typedef: ((s: string) -> Pure (typedef (fd_type s)) (requires (fd_def s)) (ensures (fun _ -> True))); } inline_for_extraction [@@noextract_to "krml"; norm_field_attr] let nonempty_field_description_t (t: Type0) = (fd: field_description_t t { fd.fd_empty == false }) [@@noextract_to "krml"] // proof-only let field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype = (s: string { fd.fd_def s }) inline_for_extraction [@@noextract_to "krml"] let field_description_nil : field_description_t field_t_nil = { fd_def = (fun _ -> false); fd_empty = true; fd_type = (fun _ -> unit); fd_typedef = (fun _ -> false_elim ()); }
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.C.Types.Base.fsti.checked", "Steel.C.Typestring.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Fields.fsti" }
[ { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.C.Typestring", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types.Base", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.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
fn: Type0 -> n: Prims.string -> t: Steel.ST.C.Types.Base.typedef ft -> fd: Steel.ST.C.Types.Fields.field_description_t fc -> Steel.ST.C.Types.Fields.nonempty_field_description_t (Steel.ST.C.Types.Fields.field_t_cons fn ft fc)
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Steel.ST.C.Types.Base.typedef", "Steel.ST.C.Types.Fields.field_description_t", "Steel.ST.C.Types.Fields.Mkfield_description_t", "Steel.ST.C.Types.Fields.field_t_cons", "Prims.op_BarBar", "Prims.op_Equality", "Steel.ST.C.Types.Fields.__proj__Mkfield_description_t__item__fd_def", "Prims.bool", "Steel.ST.C.Types.Fields.__proj__Mkfield_description_t__item__fd_type", "Steel.ST.C.Types.Fields.__proj__Mkfield_description_t__item__fd_typedef", "Steel.ST.C.Types.Fields.nonempty_field_description_t" ]
[]
false
false
false
true
false
let field_description_cons0 (fn #ft #fc: Type0) (n: string) (t: typedef ft) (fd: field_description_t fc) : Tot (nonempty_field_description_t (field_t_cons fn ft fc)) =
{ fd_def = (fun n' -> n = n' || fd.fd_def n'); fd_empty = false; fd_type = (fun n' -> if n = n' then ft else fd.fd_type n'); fd_typedef = (fun n' -> if n = n' then t else fd.fd_typedef n') }
false
Hacl.Spec.P256.PrecompTable.fst
Hacl.Spec.P256.PrecompTable.proj_point_to_list_fits
val proj_point_to_list_fits: p:S.proj_point -> Lemma (point_inv_list (proj_point_to_list p))
val proj_point_to_list_fits: p:S.proj_point -> Lemma (point_inv_list (proj_point_to_list p))
let proj_point_to_list_fits p = let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in proj_point_to_list_sub p; felem_to_list_lemma_eval pxM; felem_to_list_lemma_eval pyM; felem_to_list_lemma_eval pzM
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 97, "start_col": 0, "start_line": 88 }
module Hacl.Spec.P256.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Impl.P256.Point module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module FL = FStar.List.Tot module SPT = Hacl.Spec.PrecompBaseTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let create4_lseq (x0 x1 x2 x3:uint64) : lseq uint64 4 = let l = [x0; x1; x2; x3] in assert_norm (FL.length l = 4); Seq.seq_of_list l val create4_lemma (x0 x1 x2 x3:uint64) : Lemma (let s = create4_lseq x0 x1 x2 x3 in s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3) let create4_lemma x0 x1 x2 x3 = Seq.elim_of_list [x0; x1; x2; x3] //----------------------------------- noextract let list_as_felem4 (f:felem_list) : lseq uint64 4 = Seq.seq_of_list f <: lseq uint64 4 val felem_to_list_lemma_eval: x:S.felem -> Lemma (BD.bn_v (list_as_felem4 (felem_to_list x)) == x) let felem_to_list_lemma_eval x = let x0 = x % pow2 64 in let x1 = x / pow2 64 % pow2 64 in let x2 = x / pow2 128 % pow2 64 in let x3 = x / pow2 192 % pow2 64 in let bn_x = list_as_felem4 (felem_to_list x) in create4_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3); assert (v bn_x.[0] == x0 /\ v bn_x.[1] == x1 /\ v bn_x.[2] == x2 /\ v bn_x.[3] == x3); Hacl.Impl.P256.Bignum.bn_v_is_as_nat bn_x; assert (BD.bn_v bn_x = x0 + x1 * pow2 64 + x2 * pow2 128 + x3 * pow2 192); Hacl.Spec.PrecompBaseTable256.lemma_decompose_nat256_as_four_u64 x //-------------------------------------------- val proj_point_to_list_sub: p:S.proj_point -> Lemma (let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in let p_list = FL.(px_list @ py_list @ pz_list) in let p_lseq = Seq.seq_of_list p_list <: lseq uint64 12 in let px_lseq = Seq.seq_of_list px_list <: lseq uint64 4 in let py_lseq = Seq.seq_of_list py_list <: lseq uint64 4 in let pz_lseq = Seq.seq_of_list pz_list <: lseq uint64 4 in sub p_lseq 0 4 == px_lseq /\ sub p_lseq 4 4 == py_lseq /\ sub p_lseq 8 4 == pz_lseq) let proj_point_to_list_sub p = let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in FL.append_assoc px_list py_list pz_list; SPT.seq_of_list_append_lemma px_list py_list; SPT.seq_of_list_append_lemma FL.(px_list @ py_list) pz_list val proj_point_to_list_fits: p:S.proj_point -> Lemma (point_inv_list (proj_point_to_list p))
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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
p: Spec.P256.PointOps.proj_point -> FStar.Pervasives.Lemma (ensures Hacl.Spec.P256.PrecompTable.point_inv_list (Hacl.Spec.P256.PrecompTable.proj_point_to_list p))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.proj_point", "Prims.nat", "Hacl.Spec.P256.PrecompTable.felem_to_list_lemma_eval", "Prims.unit", "Hacl.Spec.P256.PrecompTable.proj_point_to_list_sub", "Spec.P256.PointOps.felem", "Hacl.Spec.P256.Montgomery.to_mont" ]
[]
false
false
true
false
false
let proj_point_to_list_fits p =
let px, py, pz = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in proj_point_to_list_sub p; felem_to_list_lemma_eval pxM; felem_to_list_lemma_eval pyM; felem_to_list_lemma_eval pzM
false
Steel.ST.Array.fst
Steel.ST.Array.raise_t
val raise_t (t: Type0) : Type u#1
val raise_t (t: Type0) : Type u#1
let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 60, "end_line": 27, "start_col": 0, "start_line": 27 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Type0 -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.Universe.raise_t" ]
[]
false
false
false
true
true
let raise_t (t: Type0) : Type u#1 =
FStar.Universe.raise_t t
false
Hacl.Spec.P256.PrecompTable.fst
Hacl.Spec.P256.PrecompTable.proj_point_to_list_lemma
val proj_point_to_list_lemma: p:S.proj_point -> Lemma (point_inv_list (proj_point_to_list p) /\ point_eval_list (proj_point_to_list p) == p)
val proj_point_to_list_lemma: p:S.proj_point -> Lemma (point_inv_list (proj_point_to_list p) /\ point_eval_list (proj_point_to_list p) == p)
let proj_point_to_list_lemma p = proj_point_to_list_fits p; proj_point_to_list_eval p
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 120, "start_col": 0, "start_line": 118 }
module Hacl.Spec.P256.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Impl.P256.Point module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module FL = FStar.List.Tot module SPT = Hacl.Spec.PrecompBaseTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let create4_lseq (x0 x1 x2 x3:uint64) : lseq uint64 4 = let l = [x0; x1; x2; x3] in assert_norm (FL.length l = 4); Seq.seq_of_list l val create4_lemma (x0 x1 x2 x3:uint64) : Lemma (let s = create4_lseq x0 x1 x2 x3 in s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3) let create4_lemma x0 x1 x2 x3 = Seq.elim_of_list [x0; x1; x2; x3] //----------------------------------- noextract let list_as_felem4 (f:felem_list) : lseq uint64 4 = Seq.seq_of_list f <: lseq uint64 4 val felem_to_list_lemma_eval: x:S.felem -> Lemma (BD.bn_v (list_as_felem4 (felem_to_list x)) == x) let felem_to_list_lemma_eval x = let x0 = x % pow2 64 in let x1 = x / pow2 64 % pow2 64 in let x2 = x / pow2 128 % pow2 64 in let x3 = x / pow2 192 % pow2 64 in let bn_x = list_as_felem4 (felem_to_list x) in create4_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3); assert (v bn_x.[0] == x0 /\ v bn_x.[1] == x1 /\ v bn_x.[2] == x2 /\ v bn_x.[3] == x3); Hacl.Impl.P256.Bignum.bn_v_is_as_nat bn_x; assert (BD.bn_v bn_x = x0 + x1 * pow2 64 + x2 * pow2 128 + x3 * pow2 192); Hacl.Spec.PrecompBaseTable256.lemma_decompose_nat256_as_four_u64 x //-------------------------------------------- val proj_point_to_list_sub: p:S.proj_point -> Lemma (let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in let p_list = FL.(px_list @ py_list @ pz_list) in let p_lseq = Seq.seq_of_list p_list <: lseq uint64 12 in let px_lseq = Seq.seq_of_list px_list <: lseq uint64 4 in let py_lseq = Seq.seq_of_list py_list <: lseq uint64 4 in let pz_lseq = Seq.seq_of_list pz_list <: lseq uint64 4 in sub p_lseq 0 4 == px_lseq /\ sub p_lseq 4 4 == py_lseq /\ sub p_lseq 8 4 == pz_lseq) let proj_point_to_list_sub p = let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in FL.append_assoc px_list py_list pz_list; SPT.seq_of_list_append_lemma px_list py_list; SPT.seq_of_list_append_lemma FL.(px_list @ py_list) pz_list val proj_point_to_list_fits: p:S.proj_point -> Lemma (point_inv_list (proj_point_to_list p)) let proj_point_to_list_fits p = let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in proj_point_to_list_sub p; felem_to_list_lemma_eval pxM; felem_to_list_lemma_eval pyM; felem_to_list_lemma_eval pzM val proj_point_to_list_eval: p:S.proj_point -> Lemma (point_eval_list (proj_point_to_list p) == p) let proj_point_to_list_eval p = let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in proj_point_to_list_sub p; felem_to_list_lemma_eval pxM; felem_to_list_lemma_eval pyM; felem_to_list_lemma_eval pzM; SM.lemma_to_from_mont_id px; SM.lemma_to_from_mont_id py; SM.lemma_to_from_mont_id pz
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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
p: Spec.P256.PointOps.proj_point -> FStar.Pervasives.Lemma (ensures Hacl.Spec.P256.PrecompTable.point_inv_list (Hacl.Spec.P256.PrecompTable.proj_point_to_list p) /\ Hacl.Spec.P256.PrecompTable.point_eval_list (Hacl.Spec.P256.PrecompTable.proj_point_to_list p) == p)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.proj_point", "Hacl.Spec.P256.PrecompTable.proj_point_to_list_eval", "Prims.unit", "Hacl.Spec.P256.PrecompTable.proj_point_to_list_fits" ]
[]
true
false
true
false
false
let proj_point_to_list_lemma p =
proj_point_to_list_fits p; proj_point_to_list_eval p
false
Steel.ST.Array.fst
Steel.ST.Array.lower
val lower (#t: Type) (x: raise_t t) : Tot t
val lower (#t: Type) (x: raise_t t) : Tot t
let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 37, "start_col": 0, "start_line": 36 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Steel.ST.Array.raise_t t -> t
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.Array.raise_t", "FStar.Universe.downgrade_val" ]
[]
false
false
false
true
false
let lower (#t: Type) (x: raise_t t) : Tot t =
FStar.Universe.downgrade_val x
false
Hacl.Bignum.Montgomery.fsti
Hacl.Bignum.Montgomery.bn_mont_precomp_st
val bn_mont_precomp_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
let bn_mont_precomp_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t -> n:lbignum t len -> r2:lbignum t len -> Stack (limb t) (requires fun h -> live h n /\ live h r2 /\ disjoint n r2 /\ 1 < bn_v h n /\ bn_v h n % 2 = 1 /\ pow2 (v nBits) < bn_v h n /\ v nBits / bits t < v len) (ensures fun h0 mu h1 -> modifies (loc r2) h0 h1 /\ (as_seq h1 r2, mu) == S.bn_mont_precomp (v nBits) (as_seq h0 n))
{ "file_name": "code/bignum/Hacl.Bignum.Montgomery.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 61, "start_col": 0, "start_line": 50 }
module Hacl.Bignum.Montgomery open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Bignum include Hacl.Bignum.ModInvLimb #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n)) inline_for_extraction noextract val bn_check_modulus: #t:limb_t -> #len:BN.meta_len t -> bn_check_modulus_st t len inline_for_extraction noextract let bn_precomp_r2_mod_n_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t{v nBits / bits t < v len} -> n:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h res /\ disjoint n res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_precomp_r2_mod_n (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_precomp_r2_mod_n: #t:limb_t -> k:BN.bn t -> bn_precomp_r2_mod_n_st t k.BN.len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModInvLimb.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Montgomery.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Bignum.ModInvLimb", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Prims.b2t", "Prims.op_LessThan", "Hacl.Bignum.Definitions.bn_v", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Prims.pow2", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_Division", "Lib.IntTypes.bits", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Pervasives.Native.Mktuple2", "Lib.Sequence.lseq", "Lib.Buffer.as_seq", "Hacl.Spec.Bignum.Montgomery.bn_mont_precomp" ]
[]
false
false
false
false
true
let bn_mont_precomp_st (t: limb_t) (len: BN.meta_len t) =
nBits: size_t -> n: lbignum t len -> r2: lbignum t len -> Stack (limb t) (requires fun h -> live h n /\ live h r2 /\ disjoint n r2 /\ 1 < bn_v h n /\ bn_v h n % 2 = 1 /\ pow2 (v nBits) < bn_v h n /\ v nBits / bits t < v len) (ensures fun h0 mu h1 -> modifies (loc r2) h0 h1 /\ (as_seq h1 r2, mu) == S.bn_mont_precomp (v nBits) (as_seq h0 n) )
false
Steel.ST.Reference.fst
Steel.ST.Reference.pts_to_perm
val pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ref a) : STGhost unit u (pts_to r p v) (fun _ -> pts_to r p v) True (fun _ -> p `lesser_equal_perm` full_perm)
val pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ref a) : STGhost unit u (pts_to r p v) (fun _ -> pts_to r p v) True (fun _ -> p `lesser_equal_perm` full_perm)
let pts_to_perm r = coerce_ghost (fun _ -> R.pts_to_perm r)
{ "file_name": "lib/steel/Steel.ST.Reference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 62, "start_col": 0, "start_line": 60 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Reference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference let ref (a:Type0) : Type0 = R.ref a let null (#a:Type0) : ref a = R.null #a let is_null (#a:Type0) (r:ref a) : b:bool{b <==> r == null} = R.is_null r let pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop = R.pts_to r p v let pts_to_injective_eq (#a: Type) (#opened:inames) (#p0 #p1:perm) (#v0 #v1:a) (r: ref a) : STGhost unit opened (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.pts_to_injective_eq #a #opened #p0 #p1 #(hide v0) #(hide v1) r) let pts_to_not_null #a #opened #p #v r = extract_fact #opened (pts_to r p v) (r =!= null) (R.pts_to_not_null r p v); ()
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Reference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.ST.Reference.ref a -> Steel.ST.Effect.Ghost.STGhost Prims.unit
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "Steel.ST.Reference.ref", "Steel.ST.Coercions.coerce_ghost", "Prims.unit", "Steel.Reference.pts_to", "Steel.Effect.Common.vprop", "Prims.l_True", "Prims.b2t", "Steel.FractionalPermission.lesser_equal_perm", "Steel.FractionalPermission.full_perm", "Steel.Reference.pts_to_perm" ]
[]
false
true
false
false
false
let pts_to_perm r =
coerce_ghost (fun _ -> R.pts_to_perm r)
false
Hacl.Spec.P256.PrecompTable.fst
Hacl.Spec.P256.PrecompTable.proj_point_to_list_eval
val proj_point_to_list_eval: p:S.proj_point -> Lemma (point_eval_list (proj_point_to_list p) == p)
val proj_point_to_list_eval: p:S.proj_point -> Lemma (point_eval_list (proj_point_to_list p) == p)
let proj_point_to_list_eval p = let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in proj_point_to_list_sub p; felem_to_list_lemma_eval pxM; felem_to_list_lemma_eval pyM; felem_to_list_lemma_eval pzM; SM.lemma_to_from_mont_id px; SM.lemma_to_from_mont_id py; SM.lemma_to_from_mont_id pz
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 115, "start_col": 0, "start_line": 103 }
module Hacl.Spec.P256.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Impl.P256.Point module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module FL = FStar.List.Tot module SPT = Hacl.Spec.PrecompBaseTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let create4_lseq (x0 x1 x2 x3:uint64) : lseq uint64 4 = let l = [x0; x1; x2; x3] in assert_norm (FL.length l = 4); Seq.seq_of_list l val create4_lemma (x0 x1 x2 x3:uint64) : Lemma (let s = create4_lseq x0 x1 x2 x3 in s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3) let create4_lemma x0 x1 x2 x3 = Seq.elim_of_list [x0; x1; x2; x3] //----------------------------------- noextract let list_as_felem4 (f:felem_list) : lseq uint64 4 = Seq.seq_of_list f <: lseq uint64 4 val felem_to_list_lemma_eval: x:S.felem -> Lemma (BD.bn_v (list_as_felem4 (felem_to_list x)) == x) let felem_to_list_lemma_eval x = let x0 = x % pow2 64 in let x1 = x / pow2 64 % pow2 64 in let x2 = x / pow2 128 % pow2 64 in let x3 = x / pow2 192 % pow2 64 in let bn_x = list_as_felem4 (felem_to_list x) in create4_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3); assert (v bn_x.[0] == x0 /\ v bn_x.[1] == x1 /\ v bn_x.[2] == x2 /\ v bn_x.[3] == x3); Hacl.Impl.P256.Bignum.bn_v_is_as_nat bn_x; assert (BD.bn_v bn_x = x0 + x1 * pow2 64 + x2 * pow2 128 + x3 * pow2 192); Hacl.Spec.PrecompBaseTable256.lemma_decompose_nat256_as_four_u64 x //-------------------------------------------- val proj_point_to_list_sub: p:S.proj_point -> Lemma (let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in let p_list = FL.(px_list @ py_list @ pz_list) in let p_lseq = Seq.seq_of_list p_list <: lseq uint64 12 in let px_lseq = Seq.seq_of_list px_list <: lseq uint64 4 in let py_lseq = Seq.seq_of_list py_list <: lseq uint64 4 in let pz_lseq = Seq.seq_of_list pz_list <: lseq uint64 4 in sub p_lseq 0 4 == px_lseq /\ sub p_lseq 4 4 == py_lseq /\ sub p_lseq 8 4 == pz_lseq) let proj_point_to_list_sub p = let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in FL.append_assoc px_list py_list pz_list; SPT.seq_of_list_append_lemma px_list py_list; SPT.seq_of_list_append_lemma FL.(px_list @ py_list) pz_list val proj_point_to_list_fits: p:S.proj_point -> Lemma (point_inv_list (proj_point_to_list p)) let proj_point_to_list_fits p = let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in proj_point_to_list_sub p; felem_to_list_lemma_eval pxM; felem_to_list_lemma_eval pyM; felem_to_list_lemma_eval pzM val proj_point_to_list_eval: p:S.proj_point -> Lemma (point_eval_list (proj_point_to_list p) == p)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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
p: Spec.P256.PointOps.proj_point -> FStar.Pervasives.Lemma (ensures Hacl.Spec.P256.PrecompTable.point_eval_list (Hacl.Spec.P256.PrecompTable.proj_point_to_list p) == p)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.proj_point", "Prims.nat", "Hacl.Spec.P256.Montgomery.lemma_to_from_mont_id", "Prims.unit", "Hacl.Spec.P256.PrecompTable.felem_to_list_lemma_eval", "Hacl.Spec.P256.PrecompTable.proj_point_to_list_sub", "Spec.P256.PointOps.felem", "Hacl.Spec.P256.Montgomery.to_mont" ]
[]
false
false
true
false
false
let proj_point_to_list_eval p =
let px, py, pz = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in proj_point_to_list_sub p; felem_to_list_lemma_eval pxM; felem_to_list_lemma_eval pyM; felem_to_list_lemma_eval pzM; SM.lemma_to_from_mont_id px; SM.lemma_to_from_mont_id py; SM.lemma_to_from_mont_id pz
false
Steel.ST.Array.fst
Steel.ST.Array.base_len
val base_len (#elt: Type) (b: base_t elt) : GTot nat
val base_len (#elt: Type) (b: base_t elt) : GTot nat
let base_len b = H.base_len b
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 29, "end_line": 85, "start_col": 0, "start_line": 85 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Steel.ST.Array.base_t elt -> Prims.GTot Prims.nat
Prims.GTot
[ "sometrivial" ]
[]
[ "Steel.ST.Array.base_t", "Steel.ST.HigherArray.base_len", "Steel.ST.Array.raise_t", "Prims.nat" ]
[]
false
false
false
false
false
let base_len b =
H.base_len b
false
Hacl.Bignum.Montgomery.fsti
Hacl.Bignum.Montgomery.bn_precomp_r2_mod_n_st
val bn_precomp_r2_mod_n_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
let bn_precomp_r2_mod_n_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t{v nBits / bits t < v len} -> n:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h res /\ disjoint n res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_precomp_r2_mod_n (v nBits) (as_seq h0 n))
{ "file_name": "code/bignum/Hacl.Bignum.Montgomery.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 67, "end_line": 42, "start_col": 0, "start_line": 34 }
module Hacl.Bignum.Montgomery open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Bignum include Hacl.Bignum.ModInvLimb #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n)) inline_for_extraction noextract val bn_check_modulus: #t:limb_t -> #len:BN.meta_len t -> bn_check_modulus_st t len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModInvLimb.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Montgomery.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Bignum.ModInvLimb", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.bits", "Hacl.Bignum.Definitions.lbignum", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Lib.Sequence.lseq", "Lib.Buffer.as_seq", "Hacl.Spec.Bignum.Montgomery.bn_precomp_r2_mod_n" ]
[]
false
false
false
false
true
let bn_precomp_r2_mod_n_st (t: limb_t) (len: BN.meta_len t) =
nBits: size_t{v nBits / bits t < v len} -> n: lbignum t len -> res: lbignum t len -> Stack unit (requires fun h -> live h n /\ live h res /\ disjoint n res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_precomp_r2_mod_n (v nBits) (as_seq h0 n) )
false
Steel.ST.Array.fst
Steel.ST.Array.raise
val raise (#t: Type) (x: t) : Tot (raise_t t)
val raise (#t: Type) (x: t) : Tot (raise_t t)
let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 28, "end_line": 32, "start_col": 0, "start_line": 31 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: t -> Steel.ST.Array.raise_t t
Prims.Tot
[ "total" ]
[]
[ "FStar.Universe.raise_val", "Steel.ST.Array.raise_t" ]
[]
false
false
false
true
false
let raise (#t: Type) (x: t) : Tot (raise_t t) =
FStar.Universe.raise_val x
false
Hacl.Bignum.Montgomery.fsti
Hacl.Bignum.Montgomery.bn_mont_reduction_st
val bn_mont_reduction_st : t: Hacl.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.v len + Lib.IntTypes.v len <= Lib.IntTypes.max_size_t } -> Type0
let bn_mont_reduction_st (t:limb_t) (len:size_t{0 < v len /\ v len + v len <= max_size_t}) = n:lbignum t len -> mu:limb t -> c:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h c /\ live h res /\ disjoint res n /\ disjoint res c /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc res |+| loc c) h0 h1 /\ as_seq h1 res == S.bn_mont_reduction (as_seq h0 n) mu (as_seq h0 c))
{ "file_name": "code/bignum/Hacl.Bignum.Montgomery.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 72, "end_line": 83, "start_col": 0, "start_line": 73 }
module Hacl.Bignum.Montgomery open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Bignum include Hacl.Bignum.ModInvLimb #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n)) inline_for_extraction noextract val bn_check_modulus: #t:limb_t -> #len:BN.meta_len t -> bn_check_modulus_st t len inline_for_extraction noextract let bn_precomp_r2_mod_n_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t{v nBits / bits t < v len} -> n:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h res /\ disjoint n res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_precomp_r2_mod_n (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_precomp_r2_mod_n: #t:limb_t -> k:BN.bn t -> bn_precomp_r2_mod_n_st t k.BN.len inline_for_extraction noextract let bn_mont_precomp_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t -> n:lbignum t len -> r2:lbignum t len -> Stack (limb t) (requires fun h -> live h n /\ live h r2 /\ disjoint n r2 /\ 1 < bn_v h n /\ bn_v h n % 2 = 1 /\ pow2 (v nBits) < bn_v h n /\ v nBits / bits t < v len) (ensures fun h0 mu h1 -> modifies (loc r2) h0 h1 /\ (as_seq h1 r2, mu) == S.bn_mont_precomp (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_mont_precomp: #t:limb_t -> len:BN.meta_len t -> precompr2:bn_precomp_r2_mod_n_st t len -> bn_mont_precomp_st t len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModInvLimb.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Montgomery.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Bignum.ModInvLimb", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.v len + Lib.IntTypes.v len <= Lib.IntTypes.max_size_t } -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Lib.IntTypes.op_Plus_Bang", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.op_Bar_Plus_Bar", "Lib.Buffer.loc", "Prims.eq2", "Lib.Sequence.lseq", "Lib.Buffer.as_seq", "Hacl.Spec.Bignum.Montgomery.bn_mont_reduction" ]
[]
false
false
false
false
true
let bn_mont_reduction_st (t: limb_t) (len: size_t{0 < v len /\ v len + v len <= max_size_t}) =
n: lbignum t len -> mu: limb t -> c: lbignum t (len +! len) -> res: lbignum t len -> Stack unit (requires fun h -> live h n /\ live h c /\ live h res /\ disjoint res n /\ disjoint res c /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc res |+| loc c) h0 h1 /\ as_seq h1 res == S.bn_mont_reduction (as_seq h0 n) mu (as_seq h0 c))
false
OWGCounter.ST.fst
OWGCounter.ST.release
val release (r: R.ref int) (r_mine r_other: GR.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))) : STT unit (lock_inv r r_mine r_other) (fun _ -> emp)
val release (r: R.ref int) (r_mine r_other: GR.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))) : STT unit (lock_inv r r_mine r_other) (fun _ -> emp)
let release (r:R.ref int) (r_mine r_other:GR.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))) : STT unit (lock_inv r r_mine r_other) (fun _ -> emp) = if b then begin rewrite (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)) end else begin let w = elim_exists () in rewrite (GR.pts_to r_mine half_perm (fst w) `star` GR.pts_to r_other half_perm (snd w) `star` R.pts_to r full_perm (fst w + snd w)) (GR.pts_to r_mine half_perm (snd (snd w, fst w)) `star` GR.pts_to r_other half_perm (fst (snd w, fst w)) `star` R.pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))); intro_exists (snd w, fst w) (lock_inv_predicate r r_other r_mine); rewrite (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)) end; release l
{ "file_name": "share/steel/examples/steel/OWGCounter.ST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 153, "start_col": 0, "start_line": 121 }
(* 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. Author: Aseem Rastogi *) module OWGCounter.ST open Steel.Memory open Steel.ST.Effect.Atomic open Steel.ST.Effect open Steel.ST.SpinLock open Steel.ST.Util module G = FStar.Ghost module R = Steel.ST.Reference module GR = Steel.ST.GhostReference (* * 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. * * The main idea is that the worker threads maintain ghost state * that stores their respective contributions to the counter * And the invariant between the counter and their contributions is * protected by a lock *) #set-options "--ide_id_info_off" let half_perm = half_perm full_perm /// r1 and r2 are the ghost references for the two worker threads /// /// The counter's value is the sum of values of r1 and r2 /// /// The lock contains full permission to the counter, /// and half permission each for r1 and r2 /// /// Rest of the half permissions for r1 and r2 are given to the /// two worker threads [@@ __reduce__] let lock_inv_predicate (r:R.ref int) (r1 r2:GR.ref int) : int & int -> vprop = fun w -> GR.pts_to r1 half_perm (fst w) `star` GR.pts_to r2 half_perm (snd w) `star` R.pts_to r full_perm (fst w + snd w) [@@ __reduce__] let lock_inv (r:R.ref int) (r1 r2:GR.ref int) : vprop = exists_ (lock_inv_predicate r r1 r2) /// For the auxiliary functions, we maintain r1 and r2 as /// (if b then r1 else r2) and (if b then r2 else r1), /// where b is a ghost boolean /// /// This allows us to write a single function that both threads /// can invoke by switching r1 and r2 as r_mine and r_other inline_for_extraction noextract let acquire (r:R.ref int) (r_mine r_other:GR.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))) : STT unit emp (fun _ -> lock_inv r r_mine r_other) = acquire l; if b returns STGhostT unit Set.empty _ (fun _ -> lock_inv r r_mine r_other) then begin rewrite (lock_inv _ _ _) (lock_inv r r_mine r_other) end else begin rewrite (lock_inv _ _ _) (lock_inv r r_other r_mine); let w = elim_exists () in rewrite (GR.pts_to r_other _ _ `star` GR.pts_to r_mine _ _ `star` R.pts_to _ _ _) (GR.pts_to r_other half_perm (snd (snd w, fst w)) `star` GR.pts_to r_mine half_perm (fst (snd w, fst w)) `star` R.pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))); intro_exists (snd w, fst w) (lock_inv_predicate r r_mine r_other) end inline_for_extraction
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.SpinLock.fsti.checked", "Steel.ST.Reference.fsti.checked", "Steel.ST.GhostReference.fsti.checked", "Steel.ST.Effect.Atomic.fsti.checked", "Steel.ST.Effect.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "OWGCounter.ST.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.GhostReference", "short_module": "GR" }, { "abbrev": true, "full_module": "Steel.ST.Reference", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "OWGCounter", "short_module": null }, { "abbrev": false, "full_module": "OWGCounter", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "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.ST.Reference.ref Prims.int -> r_mine: Steel.ST.GhostReference.ref Prims.int -> r_other: Steel.ST.GhostReference.ref Prims.int -> b: FStar.Ghost.erased Prims.bool -> l: Steel.ST.SpinLock.lock (OWGCounter.ST.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)) -> Steel.ST.Effect.STT Prims.unit
Steel.ST.Effect.STT
[]
[]
[ "Steel.ST.Reference.ref", "Prims.int", "Steel.ST.GhostReference.ref", "FStar.Ghost.erased", "Prims.bool", "Steel.ST.SpinLock.lock", "OWGCounter.ST.lock_inv", "FStar.Ghost.reveal", "Steel.ST.SpinLock.release", "Prims.unit", "Steel.ST.Util.rewrite", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.ST.Util.intro_exists", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.snd", "FStar.Pervasives.Native.fst", "OWGCounter.ST.lock_inv_predicate", "Steel.Effect.Common.star", "Steel.ST.GhostReference.pts_to", "OWGCounter.ST.half_perm", "Steel.ST.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Prims.op_Addition", "Steel.ST.Util.elim_exists", "Steel.Effect.Common.VStar", "Steel.Effect.Common.vprop", "Steel.Effect.Common.emp" ]
[]
false
true
false
false
false
let release (r: R.ref int) (r_mine r_other: GR.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))) : STT unit (lock_inv r r_mine r_other) (fun _ -> emp) =
if b then rewrite (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)) else (let w = elim_exists () in rewrite (((GR.pts_to r_mine half_perm (fst w)) `star` (GR.pts_to r_other half_perm (snd w))) `star` (R.pts_to r full_perm (fst w + snd w))) (((GR.pts_to r_mine half_perm (snd (snd w, fst w))) `star` (GR.pts_to r_other half_perm (fst (snd w, fst w)))) `star` (R.pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w)))); intro_exists (snd w, fst w) (lock_inv_predicate r r_other r_mine); rewrite (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))); release l
false
Hacl.Bignum.Montgomery.fsti
Hacl.Bignum.Montgomery.bn_check_modulus_st
val bn_check_modulus_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
let bn_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n))
{ "file_name": "code/bignum/Hacl.Bignum.Montgomery.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 26, "start_col": 0, "start_line": 21 }
module Hacl.Bignum.Montgomery open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Bignum include Hacl.Bignum.ModInvLimb #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModInvLimb.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Montgomery.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Bignum.ModInvLimb", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "Lib.Buffer.live", "Lib.Buffer.MUT", "Prims.l_and", "Lib.Buffer.modifies0", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Montgomery.bn_check_modulus", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq" ]
[]
false
false
false
false
true
let bn_check_modulus_st (t: limb_t) (len: BN.meta_len t) =
n: lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n))
false
Steel.ST.Array.fst
Steel.ST.Array.null_ptr
val null_ptr (elt: Type0) : ptr elt
val null_ptr (elt: Type0) : ptr elt
let null_ptr elt = H.null_ptr (raise_t elt)
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 88, "start_col": 0, "start_line": 88 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
elt: Type0 -> Steel.ST.Array.ptr elt
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.HigherArray.null_ptr", "Steel.ST.Array.raise_t", "Steel.ST.Array.ptr" ]
[]
false
false
false
true
false
let null_ptr elt =
H.null_ptr (raise_t elt)
false
Steel.ST.Array.fst
Steel.ST.Array.base_t
val base_t (elt: Type0) : Tot Type0
val base_t (elt: Type0) : Tot Type0
let base_t elt = H.base_t (raise_t elt)
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 39, "end_line": 84, "start_col": 0, "start_line": 84 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
elt: Type0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.HigherArray.base_t", "Steel.ST.Array.raise_t" ]
[]
false
false
false
true
true
let base_t elt =
H.base_t (raise_t elt)
false
Steel.ST.Array.fst
Steel.ST.Array.ptr
val ptr ([@@@unused] elt: Type0) : Type0
val ptr ([@@@unused] elt: Type0) : Type0
let ptr elt = H.ptr (raise_t elt)
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 33, "end_line": 87, "start_col": 0, "start_line": 87 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
elt: Type0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.HigherArray.ptr", "Steel.ST.Array.raise_t" ]
[]
false
false
false
true
true
let ptr elt =
H.ptr (raise_t elt)
false
Hacl.Bignum.Montgomery.fsti
Hacl.Bignum.Montgomery.bn_mont_mul_st
val bn_mont_mul_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
let bn_mont_mul_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> bM:lbignum t len -> resM:lbignum t len -> Stack unit (requires fun h -> live h aM /\ live h bM /\ live h resM /\ live h n /\ disjoint resM n /\ eq_or_disjoint aM bM /\ eq_or_disjoint aM resM /\ eq_or_disjoint bM resM) (ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\ as_seq h1 resM == S.bn_mont_mul (as_seq h0 n) mu (as_seq h0 aM) (as_seq h0 bM))
{ "file_name": "code/bignum/Hacl.Bignum.Montgomery.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 83, "end_line": 143, "start_col": 0, "start_line": 131 }
module Hacl.Bignum.Montgomery open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Bignum include Hacl.Bignum.ModInvLimb #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n)) inline_for_extraction noextract val bn_check_modulus: #t:limb_t -> #len:BN.meta_len t -> bn_check_modulus_st t len inline_for_extraction noextract let bn_precomp_r2_mod_n_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t{v nBits / bits t < v len} -> n:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h res /\ disjoint n res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_precomp_r2_mod_n (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_precomp_r2_mod_n: #t:limb_t -> k:BN.bn t -> bn_precomp_r2_mod_n_st t k.BN.len inline_for_extraction noextract let bn_mont_precomp_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t -> n:lbignum t len -> r2:lbignum t len -> Stack (limb t) (requires fun h -> live h n /\ live h r2 /\ disjoint n r2 /\ 1 < bn_v h n /\ bn_v h n % 2 = 1 /\ pow2 (v nBits) < bn_v h n /\ v nBits / bits t < v len) (ensures fun h0 mu h1 -> modifies (loc r2) h0 h1 /\ (as_seq h1 r2, mu) == S.bn_mont_precomp (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_mont_precomp: #t:limb_t -> len:BN.meta_len t -> precompr2:bn_precomp_r2_mod_n_st t len -> bn_mont_precomp_st t len inline_for_extraction noextract let bn_mont_reduction_st (t:limb_t) (len:size_t{0 < v len /\ v len + v len <= max_size_t}) = n:lbignum t len -> mu:limb t -> c:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h c /\ live h res /\ disjoint res n /\ disjoint res c /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc res |+| loc c) h0 h1 /\ as_seq h1 res == S.bn_mont_reduction (as_seq h0 n) mu (as_seq h0 c)) inline_for_extraction noextract val bn_mont_reduction: #t:limb_t -> k:BN.bn t -> bn_mont_reduction_st t k.BN.len inline_for_extraction noextract let bn_to_mont_st (t:limb_t) (nLen:BN.meta_len t) = n:lbignum t nLen -> mu:limb t -> r2:lbignum t nLen -> a:lbignum t nLen -> aM:lbignum t nLen -> Stack unit (requires fun h -> live h n /\ live h r2 /\ live h a /\ live h aM /\ disjoint a r2 /\ disjoint a n /\ disjoint a aM /\ disjoint n r2 /\ disjoint n aM /\ disjoint r2 aM) (ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\ as_seq h1 aM == S.bn_to_mont (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a)) inline_for_extraction noextract val bn_to_mont: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_to_mont_st t k.BN.len inline_for_extraction noextract let bn_from_mont_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> a:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h a /\ live h aM /\ disjoint aM a /\ disjoint aM n /\ disjoint a n) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_seq h1 a == S.bn_from_mont (as_seq h0 n) mu (as_seq h0 aM)) // This one just needs a specialized implementation of mont_reduction. No point // in doing a type class for a single function , so we take it as a parameter. inline_for_extraction noextract val bn_from_mont: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_from_mont_st t k.BN.len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModInvLimb.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Montgomery.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Bignum.ModInvLimb", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Lib.Buffer.eq_or_disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Lib.Sequence.lseq", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq", "Hacl.Spec.Bignum.Montgomery.bn_mont_mul" ]
[]
false
false
false
false
true
let bn_mont_mul_st (t: limb_t) (len: BN.meta_len t) =
n: lbignum t len -> mu: limb t -> aM: lbignum t len -> bM: lbignum t len -> resM: lbignum t len -> Stack unit (requires fun h -> live h aM /\ live h bM /\ live h resM /\ live h n /\ disjoint resM n /\ eq_or_disjoint aM bM /\ eq_or_disjoint aM resM /\ eq_or_disjoint bM resM) (ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\ as_seq h1 resM == S.bn_mont_mul (as_seq h0 n) mu (as_seq h0 aM) (as_seq h0 bM))
false
Steel.ST.Array.fst
Steel.ST.Array.base
val base (#elt: Type) (p: ptr elt) : Tot (base_t elt)
val base (#elt: Type) (p: ptr elt) : Tot (base_t elt)
let base p = H.base p
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 21, "end_line": 90, "start_col": 0, "start_line": 90 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Steel.ST.Array.ptr elt -> Steel.ST.Array.base_t elt
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.Array.ptr", "Steel.ST.HigherArray.base", "Steel.ST.Array.raise_t", "Steel.ST.Array.base_t" ]
[]
false
false
false
true
false
let base p =
H.base p
false
Steel.ST.Reference.fst
Steel.ST.Reference.cas_u32
val cas_u32 (#uses:inames) (v:Ghost.erased U32.t) (r:ref U32.t) (v_old v_new:U32.t) : STAtomicT (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to r full_perm v) (fun b -> if b then pts_to r full_perm v_new else pts_to r full_perm v)
val cas_u32 (#uses:inames) (v:Ghost.erased U32.t) (r:ref U32.t) (v_old v_new:U32.t) : STAtomicT (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to r full_perm v) (fun b -> if b then pts_to r full_perm v_new else pts_to r full_perm v)
let cas_u32 #uses v r v_old v_new = coerce_atomic (fun _ -> R.cas_pt_u32 #uses r v v_old v_new)
{ "file_name": "lib/steel/Steel.ST.Reference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 207, "start_col": 0, "start_line": 206 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Reference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference let ref (a:Type0) : Type0 = R.ref a let null (#a:Type0) : ref a = R.null #a let is_null (#a:Type0) (r:ref a) : b:bool{b <==> r == null} = R.is_null r let pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop = R.pts_to r p v let pts_to_injective_eq (#a: Type) (#opened:inames) (#p0 #p1:perm) (#v0 #v1:a) (r: ref a) : STGhost unit opened (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.pts_to_injective_eq #a #opened #p0 #p1 #(hide v0) #(hide v1) r) let pts_to_not_null #a #opened #p #v r = extract_fact #opened (pts_to r p v) (r =!= null) (R.pts_to_not_null r p v); () let pts_to_perm r = coerce_ghost (fun _ -> R.pts_to_perm r) let alloc (#a:Type) (x:a) : ST (ref a) emp (fun r -> pts_to r full_perm x) (requires True) (ensures fun r -> not (is_null r)) = let r = coerce_steel (fun _ -> R.alloc_pt x) in r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) : ST a (pts_to r p v) (fun _ -> pts_to r p v) (requires True) (ensures fun x -> x == Ghost.reveal v) = let u = coerce_steel (fun _ -> R.read_pt r) in return u let write (#a:Type0) (#v:erased a) (r:ref a) (x:a) : STT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = coerce_steel (fun _ -> R.write_pt r x); return () let free (#a:Type0) (#v:erased a) (r:ref a) : STT unit (pts_to r full_perm v) (fun _ -> emp) = coerce_steel(fun _ -> R.free_pt r); return () /// Local primitive, to be extracted to Low* EPushFrame. To remember /// that we need to call some pop_frame later, we insert some dummy /// vprop into the context. let _stack_frame : vprop = pure True let _push_frame () : STT unit emp (fun _ -> _stack_frame) = rewrite (pure True) _stack_frame /// Local primitive, to be extracted to Low* EBufCreate let _alloca (#a:Type) (x:a) : ST (ref a) emp (fun r -> pts_to r full_perm x) (requires True) (ensures fun r -> not (is_null r)) = alloc x /// Local primitive, to be extracted to Low* EPopFrame let _free_and_pop_frame (#a:Type0) (#v:erased a) (r:ref a) : STT unit (pts_to r full_perm v `star` _stack_frame) (fun _ -> emp) = free r; rewrite _stack_frame (pure True); elim_pure _ let with_local (#t: Type) (init: t) (#pre: vprop) (#ret_t: Type) (#post: ret_t -> vprop) (body: (r: ref t) -> STT ret_t (pts_to r full_perm init `star` pre) (fun v -> exists_ (pts_to r full_perm) `star` post v) ) : STF ret_t pre post True (fun _ -> True) = _push_frame (); let r = _alloca init in let v = body r in let _ = elim_exists () in _free_and_pop_frame r; return v let with_named_local (#t: Type) (init: t) (#pre: vprop) (#ret_t: Type) (#post: ret_t -> vprop) (name: string) (body: (r: ref t) -> STT ret_t (pts_to r full_perm init `star` pre) (fun v -> exists_ (pts_to r full_perm) `star` post v) ) : STF ret_t pre post True (fun _ -> True) = _push_frame (); [@(rename_let name)] let r = _alloca init in let v = body r in let _ = elim_exists () in _free_and_pop_frame r; return v let share_gen r p1 p2 = coerce_ghost (fun _ -> R.share_gen_pt r p1 p2) let share (#a:Type0) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) : STGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = coerce_ghost (fun _ -> R.share_pt r) let gather (#a:Type0) (#uses:_) (#p0 p1:perm) (#v0 #v1:erased a) (r:ref a) : STGhost unit uses (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r (sum_perm p0 p1) v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.gather_pt #a #uses #p0 #p1 #v0 #v1 r) let atomic_read_u32 r = let u = coerce_atomic (fun _ -> R.atomic_read_pt_u32 r) in return u let atomic_write_u32 r x = coerce_atomic (fun _ -> R.atomic_write_pt_u32 r x); return ()
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Reference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: FStar.Ghost.erased FStar.UInt32.t -> r: Steel.ST.Reference.ref FStar.UInt32.t -> v_old: FStar.UInt32.t -> v_new: FStar.UInt32.t -> Steel.ST.Effect.Atomic.STAtomicT (b: Prims.bool{b <==> FStar.Ghost.reveal v == v_old})
Steel.ST.Effect.Atomic.STAtomicT
[]
[]
[ "Steel.Memory.inames", "FStar.Ghost.erased", "FStar.UInt32.t", "Steel.ST.Reference.ref", "Steel.ST.Coercions.coerce_atomic", "Prims.bool", "Prims.l_iff", "Prims.b2t", "Prims.eq2", "FStar.Ghost.reveal", "Steel.Effect.Common.Observable", "Steel.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.Effect.Common.vprop", "Prims.l_True", "Prims.unit", "Steel.Reference.cas_pt_u32" ]
[]
false
true
false
false
false
let cas_u32 #uses v r v_old v_new =
coerce_atomic (fun _ -> R.cas_pt_u32 #uses r v v_old v_new)
false
Steel.ST.GhostHigherReference.fst
Steel.ST.GhostHigherReference.free
val free (#opened: _) (#a:Type) (#v:erased a) (r:ref a) : STGhostT unit opened (pts_to r full_perm v) (fun _ -> emp)
val free (#opened: _) (#a:Type) (#v:erased a) (r:ref a) : STGhostT unit opened (pts_to r full_perm v) (fun _ -> emp)
let free #_ #a #v r = let gr : R.ghost_ref a = coerce_eq (R.reveal_ghost_ref a) (Ghost.hide r.reveal) in weaken (pts_to r full_perm v) (R.ghost_pts_to gr full_perm v) (fun _ -> R.reveal_ghost_pts_to_sl gr full_perm v ); STC.coerce_ghost (fun _ -> R.ghost_free gr)
{ "file_name": "lib/steel/Steel.ST.GhostHigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 45, "end_line": 66, "start_col": 0, "start_line": 60 }
module Steel.ST.GhostHigherReference // needed because I need to know that `Steel.ST.HigherReference.ref a` // can be turned into `Steel.HigherReference.ref a` friend Steel.ST.HigherReference module RST = Steel.ST.HigherReference module R = Steel.HigherReference module STC = Steel.ST.Coercions // FIXME: WHY WHY WHY in `Ghost.reveal (ref a)` is `a` not strictly positive? [@@erasable] noeq type ref' ([@@@strictly_positive] a : Type u#1) : Type0 = | Hide: (reveal: R.ref a) -> ref' a let ref a = ref' a let pts_to r p v = RST.pts_to r.reveal p v let reveal_ref r = r.reveal let hide_ref r = Hide r let hide_reveal_ref r = () let reveal_pts_to r p x = equiv_refl (Steel.ST.HigherReference.pts_to (reveal_ref r) p x) let pts_to_injective_eq #_ #_ #p0 #p1 #v0 #v1 r = rewrite (pts_to r p0 v0) (RST.pts_to r.reveal p0 v0); rewrite (pts_to r p1 v1) (RST.pts_to r.reveal p1 v1); RST.pts_to_injective_eq #_ #_ #_ #_ #v0 #v1 r.reveal; rewrite (RST.pts_to r.reveal p0 v0) (pts_to r p0 v0); rewrite (RST.pts_to r.reveal p1 v0) (pts_to r p1 v0) let alloc #_ #a x = let gr = STC.coerce_ghost (fun _ -> R.ghost_alloc x) in let r = Hide (Ghost.reveal (coerce_eq (R.reveal_ghost_ref a) gr)) in weaken (R.ghost_pts_to gr full_perm x) (pts_to r full_perm x) (fun _ -> R.reveal_ghost_pts_to_sl gr full_perm x ); r let write #_ #a #v r x = let gr : R.ghost_ref a = coerce_eq (R.reveal_ghost_ref a) (Ghost.hide r.reveal) in weaken (pts_to r full_perm v) (R.ghost_pts_to gr full_perm v) (fun _ -> R.reveal_ghost_pts_to_sl gr full_perm v ); STC.coerce_ghost (fun _ -> R.ghost_write gr x); weaken (R.ghost_pts_to gr full_perm x) (pts_to r full_perm x) (fun _ -> R.reveal_ghost_pts_to_sl gr full_perm x )
{ "checked_file": "/", "dependencies": [ "Steel.ST.HigherReference.fst.checked", "Steel.ST.Coercions.fsti.checked", "Steel.HigherReference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.GhostHigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.Coercions", "short_module": "STC" }, { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.ST.HigherReference", "short_module": "RST" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.ST.GhostHigherReference.ref a -> Steel.ST.Effect.Ghost.STGhostT Prims.unit
Steel.ST.Effect.Ghost.STGhostT
[]
[]
[ "Steel.Memory.inames", "FStar.Ghost.erased", "Steel.ST.GhostHigherReference.ref", "Steel.ST.Coercions.coerce_ghost", "Prims.unit", "Steel.Effect.Common.VUnit", "Steel.Effect.Common.to_vprop'", "Steel.HigherReference.ghost_pts_to_sl", "Steel.FractionalPermission.full_perm", "FStar.Ghost.reveal", "Steel.Effect.Common.emp", "Steel.Effect.Common.vprop", "Prims.l_True", "Steel.HigherReference.ghost_free", "Steel.ST.Util.weaken", "Steel.ST.GhostHigherReference.pts_to", "Steel.HigherReference.ghost_pts_to", "Steel.Memory.mem", "Steel.HigherReference.reveal_ghost_pts_to_sl", "Steel.HigherReference.ghost_ref", "FStar.Pervasives.coerce_eq", "Steel.HigherReference.ref", "Steel.HigherReference.reveal_ghost_ref", "FStar.Ghost.hide", "Steel.ST.GhostHigherReference.__proj__Hide__item__reveal" ]
[]
false
true
false
false
false
let free #_ #a #v r =
let gr:R.ghost_ref a = coerce_eq (R.reveal_ghost_ref a) (Ghost.hide r.reveal) in weaken (pts_to r full_perm v) (R.ghost_pts_to gr full_perm v) (fun _ -> R.reveal_ghost_pts_to_sl gr full_perm v); STC.coerce_ghost (fun _ -> R.ghost_free gr)
false
Steel.ST.Array.fst
Steel.ST.Array.pts_to
val pts_to (#elt: Type0) (a: array elt) (p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop
val pts_to (#elt: Type0) (a: array elt) (p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop
let pts_to a p s = H.pts_to a p (seq_map raise s)
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 97, "start_col": 0, "start_line": 97 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2 let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt) let length_fits a = H.length_fits a
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.ST.Array.array elt -> p: Steel.FractionalPermission.perm -> s: FStar.Seq.Base.seq elt -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.Array.array", "Steel.FractionalPermission.perm", "FStar.Seq.Base.seq", "Steel.ST.HigherArray.pts_to", "Steel.ST.Array.raise_t", "Steel.ST.Array.seq_map", "Steel.ST.Array.raise", "Steel.Effect.Common.vprop" ]
[]
false
false
false
true
false
let pts_to a p s =
H.pts_to a p (seq_map raise s)
false
Hacl.Bignum.Montgomery.fsti
Hacl.Bignum.Montgomery.bn_to_mont_st
val bn_to_mont_st : t: Hacl.Bignum.Definitions.limb_t -> nLen: Hacl.Bignum.meta_len t -> Type0
let bn_to_mont_st (t:limb_t) (nLen:BN.meta_len t) = n:lbignum t nLen -> mu:limb t -> r2:lbignum t nLen -> a:lbignum t nLen -> aM:lbignum t nLen -> Stack unit (requires fun h -> live h n /\ live h r2 /\ live h a /\ live h aM /\ disjoint a r2 /\ disjoint a n /\ disjoint a aM /\ disjoint n r2 /\ disjoint n aM /\ disjoint r2 aM) (ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\ as_seq h1 aM == S.bn_to_mont (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a))
{ "file_name": "code/bignum/Hacl.Bignum.Montgomery.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 79, "end_line": 103, "start_col": 0, "start_line": 91 }
module Hacl.Bignum.Montgomery open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Bignum include Hacl.Bignum.ModInvLimb #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n)) inline_for_extraction noextract val bn_check_modulus: #t:limb_t -> #len:BN.meta_len t -> bn_check_modulus_st t len inline_for_extraction noextract let bn_precomp_r2_mod_n_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t{v nBits / bits t < v len} -> n:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h res /\ disjoint n res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_precomp_r2_mod_n (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_precomp_r2_mod_n: #t:limb_t -> k:BN.bn t -> bn_precomp_r2_mod_n_st t k.BN.len inline_for_extraction noextract let bn_mont_precomp_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t -> n:lbignum t len -> r2:lbignum t len -> Stack (limb t) (requires fun h -> live h n /\ live h r2 /\ disjoint n r2 /\ 1 < bn_v h n /\ bn_v h n % 2 = 1 /\ pow2 (v nBits) < bn_v h n /\ v nBits / bits t < v len) (ensures fun h0 mu h1 -> modifies (loc r2) h0 h1 /\ (as_seq h1 r2, mu) == S.bn_mont_precomp (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_mont_precomp: #t:limb_t -> len:BN.meta_len t -> precompr2:bn_precomp_r2_mod_n_st t len -> bn_mont_precomp_st t len inline_for_extraction noextract let bn_mont_reduction_st (t:limb_t) (len:size_t{0 < v len /\ v len + v len <= max_size_t}) = n:lbignum t len -> mu:limb t -> c:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h c /\ live h res /\ disjoint res n /\ disjoint res c /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc res |+| loc c) h0 h1 /\ as_seq h1 res == S.bn_mont_reduction (as_seq h0 n) mu (as_seq h0 c)) inline_for_extraction noextract val bn_mont_reduction: #t:limb_t -> k:BN.bn t -> bn_mont_reduction_st t k.BN.len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModInvLimb.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Montgomery.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Bignum.ModInvLimb", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> nLen: Hacl.Bignum.meta_len t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Lib.Sequence.lseq", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq", "Hacl.Spec.Bignum.Montgomery.bn_to_mont" ]
[]
false
false
false
false
true
let bn_to_mont_st (t: limb_t) (nLen: BN.meta_len t) =
n: lbignum t nLen -> mu: limb t -> r2: lbignum t nLen -> a: lbignum t nLen -> aM: lbignum t nLen -> Stack unit (requires fun h -> live h n /\ live h r2 /\ live h a /\ live h aM /\ disjoint a r2 /\ disjoint a n /\ disjoint a aM /\ disjoint n r2 /\ disjoint n aM /\ disjoint r2 aM) (ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\ as_seq h1 aM == S.bn_to_mont (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a))
false
Steel.ST.Reference.fst
Steel.ST.Reference.share_gen
val share_gen (#a:Type0) (#uses:_) (#p:perm) (#v: a) (r:ref a) (p1 p2: perm) : STGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (p == p1 `sum_perm` p2) (fun _ -> True)
val share_gen (#a:Type0) (#uses:_) (#p:perm) (#v: a) (r:ref a) (p1 p2: perm) : STGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (p == p1 `sum_perm` p2) (fun _ -> True)
let share_gen r p1 p2 = coerce_ghost (fun _ -> R.share_gen_pt r p1 p2)
{ "file_name": "lib/steel/Steel.ST.Reference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 48, "end_line": 174, "start_col": 0, "start_line": 172 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Reference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference let ref (a:Type0) : Type0 = R.ref a let null (#a:Type0) : ref a = R.null #a let is_null (#a:Type0) (r:ref a) : b:bool{b <==> r == null} = R.is_null r let pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop = R.pts_to r p v let pts_to_injective_eq (#a: Type) (#opened:inames) (#p0 #p1:perm) (#v0 #v1:a) (r: ref a) : STGhost unit opened (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.pts_to_injective_eq #a #opened #p0 #p1 #(hide v0) #(hide v1) r) let pts_to_not_null #a #opened #p #v r = extract_fact #opened (pts_to r p v) (r =!= null) (R.pts_to_not_null r p v); () let pts_to_perm r = coerce_ghost (fun _ -> R.pts_to_perm r) let alloc (#a:Type) (x:a) : ST (ref a) emp (fun r -> pts_to r full_perm x) (requires True) (ensures fun r -> not (is_null r)) = let r = coerce_steel (fun _ -> R.alloc_pt x) in r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) : ST a (pts_to r p v) (fun _ -> pts_to r p v) (requires True) (ensures fun x -> x == Ghost.reveal v) = let u = coerce_steel (fun _ -> R.read_pt r) in return u let write (#a:Type0) (#v:erased a) (r:ref a) (x:a) : STT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = coerce_steel (fun _ -> R.write_pt r x); return () let free (#a:Type0) (#v:erased a) (r:ref a) : STT unit (pts_to r full_perm v) (fun _ -> emp) = coerce_steel(fun _ -> R.free_pt r); return () /// Local primitive, to be extracted to Low* EPushFrame. To remember /// that we need to call some pop_frame later, we insert some dummy /// vprop into the context. let _stack_frame : vprop = pure True let _push_frame () : STT unit emp (fun _ -> _stack_frame) = rewrite (pure True) _stack_frame /// Local primitive, to be extracted to Low* EBufCreate let _alloca (#a:Type) (x:a) : ST (ref a) emp (fun r -> pts_to r full_perm x) (requires True) (ensures fun r -> not (is_null r)) = alloc x /// Local primitive, to be extracted to Low* EPopFrame let _free_and_pop_frame (#a:Type0) (#v:erased a) (r:ref a) : STT unit (pts_to r full_perm v `star` _stack_frame) (fun _ -> emp) = free r; rewrite _stack_frame (pure True); elim_pure _ let with_local (#t: Type) (init: t) (#pre: vprop) (#ret_t: Type) (#post: ret_t -> vprop) (body: (r: ref t) -> STT ret_t (pts_to r full_perm init `star` pre) (fun v -> exists_ (pts_to r full_perm) `star` post v) ) : STF ret_t pre post True (fun _ -> True) = _push_frame (); let r = _alloca init in let v = body r in let _ = elim_exists () in _free_and_pop_frame r; return v let with_named_local (#t: Type) (init: t) (#pre: vprop) (#ret_t: Type) (#post: ret_t -> vprop) (name: string) (body: (r: ref t) -> STT ret_t (pts_to r full_perm init `star` pre) (fun v -> exists_ (pts_to r full_perm) `star` post v) ) : STF ret_t pre post True (fun _ -> True) = _push_frame (); [@(rename_let name)] let r = _alloca init in let v = body r in let _ = elim_exists () in _free_and_pop_frame r; return v
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Reference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.ST.Reference.ref a -> p1: Steel.FractionalPermission.perm -> p2: Steel.FractionalPermission.perm -> Steel.ST.Effect.Ghost.STGhost Prims.unit
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "Steel.ST.Reference.ref", "Steel.ST.Coercions.coerce_ghost", "Prims.unit", "Steel.Reference.pts_to", "Steel.Effect.Common.star", "Steel.Effect.Common.vprop", "Prims.eq2", "Steel.FractionalPermission.sum_perm", "Prims.l_True", "Steel.Reference.share_gen_pt" ]
[]
false
true
false
false
false
let share_gen r p1 p2 =
coerce_ghost (fun _ -> R.share_gen_pt r p1 p2)
false
FStar.Tactics.MApply.fst
FStar.Tactics.MApply.apply_squash_or_lem
val apply_squash_or_lem : d:nat -> term -> Tac unit
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t = (* Before anything, try a vanilla apply and apply_lemma *) try apply t with | _ -> try apply (`FStar.Squash.return_squash); apply t with | _ -> try apply_lemma t with | _ -> // Fuel cutoff, just in case. if d <= 0 then fail "mapply: out of fuel" else begin let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> begin let post = `((`#post) ()) in (* unthunk *) let post = norm_term [] post in (* Is the lemma an implication? We can try to intro *) match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end | C_Total rt -> begin match unsquash_term rt with (* If the function returns a squash, just apply it, since our goals are squashed *) | Some rt -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> fail "mapply: can't apply (1)" end (* If not, we can try to introduce the squash ourselves first *) | None -> // DUPLICATED, refactor! begin let rt = norm_term [] rt in (* Is the lemma an implication? We can try to intro *) match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d-1) t | _ -> apply (`FStar.Squash.return_squash); apply t end end | _ -> fail "mapply: can't apply (2)" end
{ "file_name": "ulib/FStar.Tactics.MApply.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 91, "start_col": 0, "start_line": 32 }
module FStar.Tactics.MApply open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxHelpers open FStar.Tactics.V2.Derived open FStar.Tactics.V2.SyntaxCoercions open FStar.Tactics.Typeclasses private val push1 : (#p:Type) -> (#q:Type) -> squash (p ==> q) -> squash p -> squash q private let push1 #p #q f u = () private val push1' : (#p:Type) -> (#q:Type) -> (p ==> q) -> squash p -> squash q private let push1' #p #q f u = () (* * Some easier applying, which should prevent frustration * (or cause more when it doesn't do what you wanted to) *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.V2.Derived.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Tactics.MApply.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.Derived", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "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
d: Prims.nat -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.nat", "FStar.Tactics.NamedView.term", "FStar.Tactics.V2.Derived.try_with", "Prims.unit", "FStar.Tactics.V2.Derived.apply", "Prims.exn", "FStar.Tactics.V2.Derived.apply_lemma", "Prims.op_LessThanOrEqual", "FStar.Tactics.V2.Derived.fail", "Prims.bool", "Prims.list", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.comp", "FStar.Tactics.NamedView.inspect_comp", "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.MApply.apply_squash_or_lem", "Prims.op_Subtraction", "FStar.Reflection.V2.Formula.formula", "FStar.Reflection.V2.Formula.term_as_formula'", "FStar.Tactics.V2.Derived.norm_term", "Prims.Nil", "FStar.Pervasives.norm_step", "FStar.Reflection.V2.Derived.unsquash_term", "FStar.Stubs.Reflection.V2.Data.comp_view", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.V2.SyntaxHelpers.collect_arr", "FStar.Stubs.Tactics.V2.Builtins.tc", "FStar.Stubs.Reflection.Types.env", "FStar.Tactics.V2.Derived.cur_env" ]
[ "recursion" ]
false
true
false
false
false
let rec apply_squash_or_lem d t =
try apply t with | _ -> try (apply (`FStar.Squash.return_squash); apply t) with | _ -> try apply_lemma t with | _ -> if d <= 0 then fail "mapply: out of fuel" else let ty = tc (cur_env ()) t in let tys, c = collect_arr ty in match inspect_comp c with | C_Lemma pre post _ -> let post = `((`#post) ()) in let post = norm_term [] post in (match term_as_formula' post with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d - 1) t | _ -> fail "mapply: can't apply (1)") | C_Total rt -> (match unsquash_term rt with | Some rt -> let rt = norm_term [] rt in (match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d - 1) t | _ -> fail "mapply: can't apply (1)") | None -> let rt = norm_term [] rt in match term_as_formula' rt with | Implies p q -> apply_lemma (`push1); apply_squash_or_lem (d - 1) t | _ -> apply (`FStar.Squash.return_squash); apply t) | _ -> fail "mapply: can't apply (2)"
false
Hacl.Spec.P256.PrecompTable.fst
Hacl.Spec.P256.PrecompTable.list_as_felem4
val list_as_felem4 (f: felem_list) : lseq uint64 4
val list_as_felem4 (f: felem_list) : lseq uint64 4
let list_as_felem4 (f:felem_list) : lseq uint64 4 = Seq.seq_of_list f <: lseq uint64 4
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 33, "start_col": 0, "start_line": 32 }
module Hacl.Spec.P256.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Impl.P256.Point module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module FL = FStar.List.Tot module SPT = Hacl.Spec.PrecompBaseTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let create4_lseq (x0 x1 x2 x3:uint64) : lseq uint64 4 = let l = [x0; x1; x2; x3] in assert_norm (FL.length l = 4); Seq.seq_of_list l val create4_lemma (x0 x1 x2 x3:uint64) : Lemma (let s = create4_lseq x0 x1 x2 x3 in s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3) let create4_lemma x0 x1 x2 x3 = Seq.elim_of_list [x0; x1; x2; x3] //-----------------------------------
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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
f: Hacl.Spec.P256.PrecompTable.felem_list -> Lib.Sequence.lseq Lib.IntTypes.uint64 4
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.P256.PrecompTable.felem_list", "FStar.Seq.Base.seq_of_list", "Lib.IntTypes.uint64", "Lib.Sequence.lseq" ]
[]
false
false
false
false
false
let list_as_felem4 (f: felem_list) : lseq uint64 4 =
Seq.seq_of_list f <: lseq uint64 4
false
Hacl.Bignum.Montgomery.fsti
Hacl.Bignum.Montgomery.bn_from_mont_st
val bn_from_mont_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
let bn_from_mont_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> a:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h a /\ live h aM /\ disjoint aM a /\ disjoint aM n /\ disjoint a n) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_seq h1 a == S.bn_from_mont (as_seq h0 n) mu (as_seq h0 aM))
{ "file_name": "code/bignum/Hacl.Bignum.Montgomery.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 121, "start_col": 0, "start_line": 111 }
module Hacl.Bignum.Montgomery open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Bignum include Hacl.Bignum.ModInvLimb #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n)) inline_for_extraction noextract val bn_check_modulus: #t:limb_t -> #len:BN.meta_len t -> bn_check_modulus_st t len inline_for_extraction noextract let bn_precomp_r2_mod_n_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t{v nBits / bits t < v len} -> n:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h res /\ disjoint n res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_precomp_r2_mod_n (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_precomp_r2_mod_n: #t:limb_t -> k:BN.bn t -> bn_precomp_r2_mod_n_st t k.BN.len inline_for_extraction noextract let bn_mont_precomp_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t -> n:lbignum t len -> r2:lbignum t len -> Stack (limb t) (requires fun h -> live h n /\ live h r2 /\ disjoint n r2 /\ 1 < bn_v h n /\ bn_v h n % 2 = 1 /\ pow2 (v nBits) < bn_v h n /\ v nBits / bits t < v len) (ensures fun h0 mu h1 -> modifies (loc r2) h0 h1 /\ (as_seq h1 r2, mu) == S.bn_mont_precomp (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_mont_precomp: #t:limb_t -> len:BN.meta_len t -> precompr2:bn_precomp_r2_mod_n_st t len -> bn_mont_precomp_st t len inline_for_extraction noextract let bn_mont_reduction_st (t:limb_t) (len:size_t{0 < v len /\ v len + v len <= max_size_t}) = n:lbignum t len -> mu:limb t -> c:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h c /\ live h res /\ disjoint res n /\ disjoint res c /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc res |+| loc c) h0 h1 /\ as_seq h1 res == S.bn_mont_reduction (as_seq h0 n) mu (as_seq h0 c)) inline_for_extraction noextract val bn_mont_reduction: #t:limb_t -> k:BN.bn t -> bn_mont_reduction_st t k.BN.len inline_for_extraction noextract let bn_to_mont_st (t:limb_t) (nLen:BN.meta_len t) = n:lbignum t nLen -> mu:limb t -> r2:lbignum t nLen -> a:lbignum t nLen -> aM:lbignum t nLen -> Stack unit (requires fun h -> live h n /\ live h r2 /\ live h a /\ live h aM /\ disjoint a r2 /\ disjoint a n /\ disjoint a aM /\ disjoint n r2 /\ disjoint n aM /\ disjoint r2 aM) (ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\ as_seq h1 aM == S.bn_to_mont (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a)) inline_for_extraction noextract val bn_to_mont: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_to_mont_st t k.BN.len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModInvLimb.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Montgomery.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Bignum.ModInvLimb", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Lib.Sequence.lseq", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq", "Hacl.Spec.Bignum.Montgomery.bn_from_mont" ]
[]
false
false
false
false
true
let bn_from_mont_st (t: limb_t) (len: BN.meta_len t) =
n: lbignum t len -> mu: limb t -> aM: lbignum t len -> a: lbignum t len -> Stack unit (requires fun h -> live h n /\ live h a /\ live h aM /\ disjoint aM a /\ disjoint aM n /\ disjoint a n ) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_seq h1 a == S.bn_from_mont (as_seq h0 n) mu (as_seq h0 aM))
false
Hacl.Spec.P256.PrecompTable.fst
Hacl.Spec.P256.PrecompTable.create4_lseq
val create4_lseq (x0 x1 x2 x3: uint64) : lseq uint64 4
val create4_lseq (x0 x1 x2 x3: uint64) : lseq uint64 4
let create4_lseq (x0 x1 x2 x3:uint64) : lseq uint64 4 = let l = [x0; x1; x2; x3] in assert_norm (FL.length l = 4); Seq.seq_of_list l
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 20, "start_col": 0, "start_line": 17 }
module Hacl.Spec.P256.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Impl.P256.Point module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module FL = FStar.List.Tot module SPT = Hacl.Spec.PrecompBaseTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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
x0: Lib.IntTypes.uint64 -> x1: Lib.IntTypes.uint64 -> x2: Lib.IntTypes.uint64 -> x3: Lib.IntTypes.uint64 -> Lib.Sequence.lseq Lib.IntTypes.uint64 4
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.uint64", "FStar.Seq.Base.seq_of_list", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length", "Prims.list", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.Cons", "Prims.Nil", "Lib.Sequence.lseq" ]
[]
false
false
false
false
false
let create4_lseq (x0 x1 x2 x3: uint64) : lseq uint64 4 =
let l = [x0; x1; x2; x3] in assert_norm (FL.length l = 4); Seq.seq_of_list l
false
Hacl.Bignum.Montgomery.fsti
Hacl.Bignum.Montgomery.bn_mont_one_st
val bn_mont_one_st : t: Hacl.Bignum.Definitions.limb_t -> nLen: Hacl.Bignum.meta_len t -> Type0
let bn_mont_one_st (t:limb_t) (nLen:BN.meta_len t) = n:lbignum t nLen -> mu:limb t -> r2:lbignum t nLen -> oneM:lbignum t nLen -> Stack unit (requires fun h -> live h n /\ live h r2 /\ live h oneM /\ disjoint n r2 /\ disjoint n oneM /\ disjoint r2 oneM) (ensures fun h0 _ h1 -> modifies (loc oneM) h0 h1 /\ as_seq h1 oneM == S.bn_mont_one (as_seq h0 n) mu (as_seq h0 r2))
{ "file_name": "code/bignum/Hacl.Bignum.Montgomery.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 205, "start_col": 0, "start_line": 195 }
module Hacl.Bignum.Montgomery open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Bignum include Hacl.Bignum.ModInvLimb #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n)) inline_for_extraction noextract val bn_check_modulus: #t:limb_t -> #len:BN.meta_len t -> bn_check_modulus_st t len inline_for_extraction noextract let bn_precomp_r2_mod_n_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t{v nBits / bits t < v len} -> n:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h res /\ disjoint n res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_precomp_r2_mod_n (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_precomp_r2_mod_n: #t:limb_t -> k:BN.bn t -> bn_precomp_r2_mod_n_st t k.BN.len inline_for_extraction noextract let bn_mont_precomp_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t -> n:lbignum t len -> r2:lbignum t len -> Stack (limb t) (requires fun h -> live h n /\ live h r2 /\ disjoint n r2 /\ 1 < bn_v h n /\ bn_v h n % 2 = 1 /\ pow2 (v nBits) < bn_v h n /\ v nBits / bits t < v len) (ensures fun h0 mu h1 -> modifies (loc r2) h0 h1 /\ (as_seq h1 r2, mu) == S.bn_mont_precomp (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_mont_precomp: #t:limb_t -> len:BN.meta_len t -> precompr2:bn_precomp_r2_mod_n_st t len -> bn_mont_precomp_st t len inline_for_extraction noextract let bn_mont_reduction_st (t:limb_t) (len:size_t{0 < v len /\ v len + v len <= max_size_t}) = n:lbignum t len -> mu:limb t -> c:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h c /\ live h res /\ disjoint res n /\ disjoint res c /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc res |+| loc c) h0 h1 /\ as_seq h1 res == S.bn_mont_reduction (as_seq h0 n) mu (as_seq h0 c)) inline_for_extraction noextract val bn_mont_reduction: #t:limb_t -> k:BN.bn t -> bn_mont_reduction_st t k.BN.len inline_for_extraction noextract let bn_to_mont_st (t:limb_t) (nLen:BN.meta_len t) = n:lbignum t nLen -> mu:limb t -> r2:lbignum t nLen -> a:lbignum t nLen -> aM:lbignum t nLen -> Stack unit (requires fun h -> live h n /\ live h r2 /\ live h a /\ live h aM /\ disjoint a r2 /\ disjoint a n /\ disjoint a aM /\ disjoint n r2 /\ disjoint n aM /\ disjoint r2 aM) (ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\ as_seq h1 aM == S.bn_to_mont (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a)) inline_for_extraction noextract val bn_to_mont: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_to_mont_st t k.BN.len inline_for_extraction noextract let bn_from_mont_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> a:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h a /\ live h aM /\ disjoint aM a /\ disjoint aM n /\ disjoint a n) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_seq h1 a == S.bn_from_mont (as_seq h0 n) mu (as_seq h0 aM)) // This one just needs a specialized implementation of mont_reduction. No point // in doing a type class for a single function , so we take it as a parameter. inline_for_extraction noextract val bn_from_mont: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_from_mont_st t k.BN.len inline_for_extraction noextract let bn_mont_mul_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> bM:lbignum t len -> resM:lbignum t len -> Stack unit (requires fun h -> live h aM /\ live h bM /\ live h resM /\ live h n /\ disjoint resM n /\ eq_or_disjoint aM bM /\ eq_or_disjoint aM resM /\ eq_or_disjoint bM resM) (ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\ as_seq h1 resM == S.bn_mont_mul (as_seq h0 n) mu (as_seq h0 aM) (as_seq h0 bM)) /// This one needs both the type class and a specialized montgomery reduction. inline_for_extraction noextract val bn_mont_mul: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_mont_mul_st t k.BN.len inline_for_extraction noextract let bn_mont_sqr_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> resM:lbignum t len -> Stack unit (requires fun h -> live h aM /\ live h resM /\ live h n /\ disjoint resM n /\ eq_or_disjoint aM resM) (ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\ as_seq h1 resM == S.bn_mont_sqr (as_seq h0 n) mu (as_seq h0 aM)) /// This one needs both the type class and a specialized montgomery reduction. inline_for_extraction noextract val bn_mont_sqr: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_mont_sqr_st t k.BN.len inline_for_extraction noextract class mont (t:limb_t) = { bn: BN.bn t; mont_check: bn_check_modulus_st t bn.BN.len; precomp: bn_precomp_r2_mod_n_st t bn.BN.len; reduction: bn_mont_reduction_st t bn.BN.len; to: bn_to_mont_st t bn.BN.len; from: bn_from_mont_st t bn.BN.len; mul: bn_mont_mul_st t bn.BN.len; sqr: bn_mont_sqr_st t bn.BN.len; } /// Encoding type-class hierarchies via a hook for type class resolution. inline_for_extraction noextract instance bn_of_mont (t:limb_t) (x:mont t) : BN.bn t = x.bn // A completely run-time-only instance where the functions above exist in the C code. inline_for_extraction noextract val mk_runtime_mont: #t:limb_t -> len:BN.meta_len t -> mont t val mk_runtime_mont_len_lemma: #t:limb_t -> len:BN.meta_len t -> Lemma ((mk_runtime_mont #t len).bn.BN.len == len) [SMTPat (mk_runtime_mont #t len)]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModInvLimb.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Montgomery.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Bignum.ModInvLimb", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> nLen: Hacl.Bignum.meta_len t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Lib.Sequence.lseq", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq", "Hacl.Spec.Bignum.Montgomery.bn_mont_one" ]
[]
false
false
false
false
true
let bn_mont_one_st (t: limb_t) (nLen: BN.meta_len t) =
n: lbignum t nLen -> mu: limb t -> r2: lbignum t nLen -> oneM: lbignum t nLen -> Stack unit (requires fun h -> live h n /\ live h r2 /\ live h oneM /\ disjoint n r2 /\ disjoint n oneM /\ disjoint r2 oneM) (ensures fun h0 _ h1 -> modifies (loc oneM) h0 h1 /\ as_seq h1 oneM == S.bn_mont_one (as_seq h0 n) mu (as_seq h0 r2))
false
Hacl.Bignum.Montgomery.fsti
Hacl.Bignum.Montgomery.bn_mont_sqr_st
val bn_mont_sqr_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
let bn_mont_sqr_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> resM:lbignum t len -> Stack unit (requires fun h -> live h aM /\ live h resM /\ live h n /\ disjoint resM n /\ eq_or_disjoint aM resM) (ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\ as_seq h1 resM == S.bn_mont_sqr (as_seq h0 n) mu (as_seq h0 aM))
{ "file_name": "code/bignum/Hacl.Bignum.Montgomery.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 162, "start_col": 0, "start_line": 152 }
module Hacl.Bignum.Montgomery open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Bignum include Hacl.Bignum.ModInvLimb #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let bn_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_check_modulus (as_seq h0 n)) inline_for_extraction noextract val bn_check_modulus: #t:limb_t -> #len:BN.meta_len t -> bn_check_modulus_st t len inline_for_extraction noextract let bn_precomp_r2_mod_n_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t{v nBits / bits t < v len} -> n:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h res /\ disjoint n res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_precomp_r2_mod_n (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_precomp_r2_mod_n: #t:limb_t -> k:BN.bn t -> bn_precomp_r2_mod_n_st t k.BN.len inline_for_extraction noextract let bn_mont_precomp_st (t:limb_t) (len:BN.meta_len t) = nBits:size_t -> n:lbignum t len -> r2:lbignum t len -> Stack (limb t) (requires fun h -> live h n /\ live h r2 /\ disjoint n r2 /\ 1 < bn_v h n /\ bn_v h n % 2 = 1 /\ pow2 (v nBits) < bn_v h n /\ v nBits / bits t < v len) (ensures fun h0 mu h1 -> modifies (loc r2) h0 h1 /\ (as_seq h1 r2, mu) == S.bn_mont_precomp (v nBits) (as_seq h0 n)) inline_for_extraction noextract val bn_mont_precomp: #t:limb_t -> len:BN.meta_len t -> precompr2:bn_precomp_r2_mod_n_st t len -> bn_mont_precomp_st t len inline_for_extraction noextract let bn_mont_reduction_st (t:limb_t) (len:size_t{0 < v len /\ v len + v len <= max_size_t}) = n:lbignum t len -> mu:limb t -> c:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h c /\ live h res /\ disjoint res n /\ disjoint res c /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc res |+| loc c) h0 h1 /\ as_seq h1 res == S.bn_mont_reduction (as_seq h0 n) mu (as_seq h0 c)) inline_for_extraction noextract val bn_mont_reduction: #t:limb_t -> k:BN.bn t -> bn_mont_reduction_st t k.BN.len inline_for_extraction noextract let bn_to_mont_st (t:limb_t) (nLen:BN.meta_len t) = n:lbignum t nLen -> mu:limb t -> r2:lbignum t nLen -> a:lbignum t nLen -> aM:lbignum t nLen -> Stack unit (requires fun h -> live h n /\ live h r2 /\ live h a /\ live h aM /\ disjoint a r2 /\ disjoint a n /\ disjoint a aM /\ disjoint n r2 /\ disjoint n aM /\ disjoint r2 aM) (ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\ as_seq h1 aM == S.bn_to_mont (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a)) inline_for_extraction noextract val bn_to_mont: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_to_mont_st t k.BN.len inline_for_extraction noextract let bn_from_mont_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> a:lbignum t len -> Stack unit (requires fun h -> live h n /\ live h a /\ live h aM /\ disjoint aM a /\ disjoint aM n /\ disjoint a n) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ as_seq h1 a == S.bn_from_mont (as_seq h0 n) mu (as_seq h0 aM)) // This one just needs a specialized implementation of mont_reduction. No point // in doing a type class for a single function , so we take it as a parameter. inline_for_extraction noextract val bn_from_mont: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_from_mont_st t k.BN.len inline_for_extraction noextract let bn_mont_mul_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> mu:limb t -> aM:lbignum t len -> bM:lbignum t len -> resM:lbignum t len -> Stack unit (requires fun h -> live h aM /\ live h bM /\ live h resM /\ live h n /\ disjoint resM n /\ eq_or_disjoint aM bM /\ eq_or_disjoint aM resM /\ eq_or_disjoint bM resM) (ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\ as_seq h1 resM == S.bn_mont_mul (as_seq h0 n) mu (as_seq h0 aM) (as_seq h0 bM)) /// This one needs both the type class and a specialized montgomery reduction. inline_for_extraction noextract val bn_mont_mul: #t:limb_t -> k:BN.bn t -> mr:bn_mont_reduction_st t k.BN.len -> bn_mont_mul_st t k.BN.len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModInvLimb.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Montgomery.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Bignum.ModInvLimb", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Lib.Buffer.eq_or_disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Lib.Sequence.lseq", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq", "Hacl.Spec.Bignum.Montgomery.bn_mont_sqr" ]
[]
false
false
false
false
true
let bn_mont_sqr_st (t: limb_t) (len: BN.meta_len t) =
n: lbignum t len -> mu: limb t -> aM: lbignum t len -> resM: lbignum t len -> Stack unit (requires fun h -> live h aM /\ live h resM /\ live h n /\ disjoint resM n /\ eq_or_disjoint aM resM) (ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\ as_seq h1 resM == S.bn_mont_sqr (as_seq h0 n) mu (as_seq h0 aM))
false
Steel.ST.Array.fst
Steel.ST.Array.compare_inv
val compare_inv : a0: Steel.ST.Array.array t -> a1: Steel.ST.Array.array t -> s0: FStar.Seq.Base.seq t -> s1: FStar.Seq.Base.seq t -> l: FStar.SizeT.t -> ctr: Steel.ST.Reference.ref (FStar.Pervasives.Native.option FStar.SizeT.t) -> b: Prims.bool -> Steel.Effect.Common.vprop
let compare_inv (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (s0: Seq.seq t) (s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (b: bool) = pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (x:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l b))
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 267, "start_col": 0, "start_line": 255 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2 let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt) let length_fits a = H.length_fits a let pts_to a p s = H.pts_to a p (seq_map raise s) let pts_to_length a s = H.pts_to_length a _ let h_array_eq' (#t: Type u#1) (a1 a2: H.array t) : Lemma (requires ( dfst a1 == dfst a2 /\ (Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2) )) (ensures ( a1 == a2 )) = () let pts_to_not_null #_ #t #p a s = let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in assert (a =!= H.null #(raise_t t)); Classical.move_requires (h_array_eq' a) (H.null #(raise_t t)); noop () let pts_to_inj a p1 s1 p2 s2 = H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2) /// Non-selector operations. let malloc x n = let res = H.malloc (raise x) n in assert (seq_map raise (Seq.create (US.v n) x) `Seq.equal` Seq.create (US.v n) (raise x)); rewrite (H.pts_to res _ _) (pts_to res _ _); return res let free #_ x = let s = elim_exists () in rewrite (pts_to x _ _) (H.pts_to x P.full_perm (seq_map raise s)); H.free x let share #_ #_ #x a p p1 p2 = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); H.share a p p1 p2; rewrite (H.pts_to a p1 _) (pts_to a p1 x); rewrite (H.pts_to a p2 _) (pts_to a p2 x) let gather #_ #_ a #x1 p1 #x2 p2 = rewrite (pts_to a p1 _) (H.pts_to a p1 (seq_map raise x1)); rewrite (pts_to a p2 _) (H.pts_to a p2 (seq_map raise x2)); H.gather a p1 p2; rewrite (H.pts_to a _ _) (pts_to _ _ _) let index #_ #p a #s i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise s)); let res = H.index a i in rewrite (H.pts_to _ _ _) (pts_to _ _ _); return (lower res) let upd #_ a #s i v = rewrite (pts_to a _ _) (H.pts_to a P.full_perm (seq_map raise s)); H.upd a i (raise v); assert (seq_map raise (Seq.upd s (US.v i) v) `Seq.equal` Seq.upd (seq_map raise s) (US.v i) (raise v)); rewrite (H.pts_to _ _ _) (pts_to _ _ _) let ghost_join #_ #_ #x1 #x2 #p a1 a2 h = rewrite (pts_to a1 _ _) (H.pts_to a1 p (seq_map raise x1)); rewrite (pts_to a2 _ _) (H.pts_to a2 p (seq_map raise x2)); H.ghost_join a1 a2 h; assert (seq_map raise (x1 `Seq.append` x2) `Seq.equal` (seq_map raise x1 `Seq.append` seq_map raise x2)); rewrite (H.pts_to _ _ _) (H.pts_to (merge a1 a2) p (seq_map raise (x1 `Seq.append` x2))); rewrite (H.pts_to _ _ _) (pts_to (merge a1 a2) _ _) let ptr_shift p off = H.ptr_shift p off let ghost_split #_ #_ #x #p a i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); let _ = H.ghost_split a i in //H.ghost_split a i; assert (seq_map raise (Seq.slice x 0 (US.v i)) `Seq.equal` Seq.slice (seq_map raise x) 0 (US.v i)); rewrite (H.pts_to (H.split_l a i) _ _) (H.pts_to (split_l a i) p (seq_map raise (Seq.slice x 0 (US.v i)))); rewrite (H.pts_to (split_l a i) _ _) (pts_to (split_l a i) _ _); assert (seq_map raise (Seq.slice x (US.v i) (Seq.length x)) `Seq.equal` Seq.slice (seq_map raise x) (US.v i) (Seq.length (seq_map raise x))); Seq.lemma_split x (US.v i); rewrite (H.pts_to (H.split_r a i) _ _) (H.pts_to (split_r a i) p (seq_map raise (Seq.slice x (US.v i) (Seq.length x)))); rewrite (H.pts_to (split_r a i) _ _) (pts_to (split_r a i) _ _) let memcpy a0 a1 l = H.memcpy a0 a1 l //////////////////////////////////////////////////////////////////////////////// // compare //////////////////////////////////////////////////////////////////////////////// module R = Steel.ST.Reference #push-options "--fuel 0 --ifuel 1 --z3rlimit_factor 2" let equal_up_to #t (s0: Seq.seq t) (s1: Seq.seq t) (v : option US.t) : prop = Seq.length s0 = Seq.length s1 /\ (match v with | None -> Ghost.reveal s0 =!= Ghost.reveal s1 | Some v -> US.v v <= Seq.length s0 /\ Seq.slice s0 0 (US.v v) `Seq.equal` Seq.slice s1 0 (US.v v)) let within_bounds (x:option US.t) (l:US.t) (b:Ghost.erased bool) : prop = if b then Some? x /\ US.(Some?.v x <^ l) else None? x \/ US.(Some?.v x >=^ l)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.Reference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a0: Steel.ST.Array.array t -> a1: Steel.ST.Array.array t -> s0: FStar.Seq.Base.seq t -> s1: FStar.Seq.Base.seq t -> l: FStar.SizeT.t -> ctr: Steel.ST.Reference.ref (FStar.Pervasives.Native.option FStar.SizeT.t) -> b: Prims.bool -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Steel.FractionalPermission.perm", "Steel.ST.Array.array", "FStar.Seq.Base.seq", "FStar.SizeT.t", "Steel.ST.Reference.ref", "FStar.Pervasives.Native.option", "Prims.bool", "Steel.Effect.Common.star", "Steel.ST.Array.pts_to", "Steel.ST.Util.exists_", "Steel.ST.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.ST.Util.pure", "Steel.ST.Array.equal_up_to", "Steel.ST.Array.within_bounds", "FStar.Ghost.hide", "Steel.Effect.Common.vprop" ]
[]
false
false
false
false
false
let compare_inv (#t: eqtype) (#p0 #p1: perm) (a0 a1: array t) (s0 s1: Seq.seq t) (l: US.t) (ctr: R.ref (option US.t)) (b: bool) =
((pts_to a0 p0 s0) `star` (pts_to a1 p1 s1)) `star` (exists_ (fun (x: option US.t) -> ((R.pts_to ctr Steel.FractionalPermission.full_perm x) `star` (pure (equal_up_to s0 s1 x))) `star` (pure (within_bounds x l b))))
false
Hacl.Spec.P256.PrecompTable.fst
Hacl.Spec.P256.PrecompTable.felem_to_list_lemma_eval
val felem_to_list_lemma_eval: x:S.felem -> Lemma (BD.bn_v (list_as_felem4 (felem_to_list x)) == x)
val felem_to_list_lemma_eval: x:S.felem -> Lemma (BD.bn_v (list_as_felem4 (felem_to_list x)) == x)
let felem_to_list_lemma_eval x = let x0 = x % pow2 64 in let x1 = x / pow2 64 % pow2 64 in let x2 = x / pow2 128 % pow2 64 in let x3 = x / pow2 192 % pow2 64 in let bn_x = list_as_felem4 (felem_to_list x) in create4_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3); assert (v bn_x.[0] == x0 /\ v bn_x.[1] == x1 /\ v bn_x.[2] == x2 /\ v bn_x.[3] == x3); Hacl.Impl.P256.Bignum.bn_v_is_as_nat bn_x; assert (BD.bn_v bn_x = x0 + x1 * pow2 64 + x2 * pow2 128 + x3 * pow2 192); Hacl.Spec.PrecompBaseTable256.lemma_decompose_nat256_as_four_u64 x
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 49, "start_col": 0, "start_line": 39 }
module Hacl.Spec.P256.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Impl.P256.Point module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module FL = FStar.List.Tot module SPT = Hacl.Spec.PrecompBaseTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let create4_lseq (x0 x1 x2 x3:uint64) : lseq uint64 4 = let l = [x0; x1; x2; x3] in assert_norm (FL.length l = 4); Seq.seq_of_list l val create4_lemma (x0 x1 x2 x3:uint64) : Lemma (let s = create4_lseq x0 x1 x2 x3 in s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3) let create4_lemma x0 x1 x2 x3 = Seq.elim_of_list [x0; x1; x2; x3] //----------------------------------- noextract let list_as_felem4 (f:felem_list) : lseq uint64 4 = Seq.seq_of_list f <: lseq uint64 4 val felem_to_list_lemma_eval: x:S.felem -> Lemma (BD.bn_v (list_as_felem4 (felem_to_list x)) == x)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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
x: Spec.P256.PointOps.felem -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.P256.PrecompTable.list_as_felem4 (Hacl.Spec.P256.PrecompTable.felem_to_list x)) == x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.felem", "Hacl.Spec.PrecompBaseTable256.lemma_decompose_nat256_as_four_u64", "Prims.unit", "Prims._assert", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.U64", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.pow2", "Hacl.Impl.P256.Bignum.bn_v_is_as_nat", "Prims.l_and", "Prims.eq2", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Lib.IntTypes.uint64", "Hacl.Spec.P256.PrecompTable.create4_lemma", "Lib.IntTypes.u64", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Hacl.Spec.P256.PrecompTable.list_as_felem4", "Hacl.Spec.P256.PrecompTable.felem_to_list", "Prims.op_Modulus", "Prims.op_Division" ]
[]
true
false
true
false
false
let felem_to_list_lemma_eval x =
let x0 = x % pow2 64 in let x1 = x / pow2 64 % pow2 64 in let x2 = x / pow2 128 % pow2 64 in let x3 = x / pow2 192 % pow2 64 in let bn_x = list_as_felem4 (felem_to_list x) in create4_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3); assert (v bn_x.[ 0 ] == x0 /\ v bn_x.[ 1 ] == x1 /\ v bn_x.[ 2 ] == x2 /\ v bn_x.[ 3 ] == x3); Hacl.Impl.P256.Bignum.bn_v_is_as_nat bn_x; assert (BD.bn_v bn_x = x0 + x1 * pow2 64 + x2 * pow2 128 + x3 * pow2 192); Hacl.Spec.PrecompBaseTable256.lemma_decompose_nat256_as_four_u64 x
false
Hacl.Spec.P256.PrecompTable.fst
Hacl.Spec.P256.PrecompTable.create4_lemma
val create4_lemma (x0 x1 x2 x3:uint64) : Lemma (let s = create4_lseq x0 x1 x2 x3 in s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3)
val create4_lemma (x0 x1 x2 x3:uint64) : Lemma (let s = create4_lseq x0 x1 x2 x3 in s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3)
let create4_lemma x0 x1 x2 x3 = Seq.elim_of_list [x0; x1; x2; x3]
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 27, "start_col": 0, "start_line": 26 }
module Hacl.Spec.P256.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Impl.P256.Point module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module FL = FStar.List.Tot module SPT = Hacl.Spec.PrecompBaseTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let create4_lseq (x0 x1 x2 x3:uint64) : lseq uint64 4 = let l = [x0; x1; x2; x3] in assert_norm (FL.length l = 4); Seq.seq_of_list l val create4_lemma (x0 x1 x2 x3:uint64) : Lemma (let s = create4_lseq x0 x1 x2 x3 in
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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
x0: Lib.IntTypes.uint64 -> x1: Lib.IntTypes.uint64 -> x2: Lib.IntTypes.uint64 -> x3: Lib.IntTypes.uint64 -> FStar.Pervasives.Lemma (ensures (let s = Hacl.Spec.P256.PrecompTable.create4_lseq x0 x1 x2 x3 in s.[ 0 ] == x0 /\ s.[ 1 ] == x1 /\ s.[ 2 ] == x2 /\ s.[ 3 ] == x3))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.uint64", "FStar.Seq.Properties.elim_of_list", "Prims.Cons", "Prims.Nil", "Prims.unit" ]
[]
true
false
true
false
false
let create4_lemma x0 x1 x2 x3 =
Seq.elim_of_list [x0; x1; x2; x3]
false
Steel.ST.Array.fst
Steel.ST.Array.seq_map_raise_inj
val seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)]
val seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)]
let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2)
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 58, "end_line": 76, "start_col": 0, "start_line": 68 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = ()
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s1: FStar.Seq.Base.seq elt -> s2: FStar.Seq.Base.seq elt -> FStar.Pervasives.Lemma (requires Steel.ST.Array.seq_map Steel.ST.Array.raise s1 == Steel.ST.Array.seq_map Steel.ST.Array.raise s2) (ensures s1 == s2) [ SMTPat (Steel.ST.Array.seq_map Steel.ST.Array.raise s1); SMTPat (Steel.ST.Array.seq_map Steel.ST.Array.raise s2) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Prims._assert", "FStar.Seq.Base.equal", "Steel.ST.Array.seq_map", "Steel.ST.Array.raise_t", "Steel.ST.Array.lower", "Steel.ST.Array.raise", "Prims.unit", "Prims.eq2", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] =
assert ((seq_map lower (seq_map raise s1)) `Seq.equal` s1); assert ((seq_map lower (seq_map raise s2)) `Seq.equal` s2)
false
Steel.ST.Array.fst
Steel.ST.Array.pts_to_range_body
val pts_to_range_body (#elt: Type0) (a: array elt) (i j: nat) (p: P.perm) (s: Seq.seq elt) (sq: squash (i <= j /\ j <= length a)) : Tot vprop
val pts_to_range_body (#elt: Type0) (a: array elt) (i j: nat) (p: P.perm) (s: Seq.seq elt) (sq: squash (i <= j /\ j <= length a)) : Tot vprop
let pts_to_range_body (#elt: Type0) (a: array elt) (i j: nat) (p: P.perm) (s: Seq.seq elt) (sq: squash (i <= j /\ j <= length a)) : Tot vprop = pts_to (array_slice a i j sq) p s
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 576, "start_col": 0, "start_line": 570 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2 let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt) let length_fits a = H.length_fits a let pts_to a p s = H.pts_to a p (seq_map raise s) let pts_to_length a s = H.pts_to_length a _ let h_array_eq' (#t: Type u#1) (a1 a2: H.array t) : Lemma (requires ( dfst a1 == dfst a2 /\ (Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2) )) (ensures ( a1 == a2 )) = () let pts_to_not_null #_ #t #p a s = let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in assert (a =!= H.null #(raise_t t)); Classical.move_requires (h_array_eq' a) (H.null #(raise_t t)); noop () let pts_to_inj a p1 s1 p2 s2 = H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2) /// Non-selector operations. let malloc x n = let res = H.malloc (raise x) n in assert (seq_map raise (Seq.create (US.v n) x) `Seq.equal` Seq.create (US.v n) (raise x)); rewrite (H.pts_to res _ _) (pts_to res _ _); return res let free #_ x = let s = elim_exists () in rewrite (pts_to x _ _) (H.pts_to x P.full_perm (seq_map raise s)); H.free x let share #_ #_ #x a p p1 p2 = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); H.share a p p1 p2; rewrite (H.pts_to a p1 _) (pts_to a p1 x); rewrite (H.pts_to a p2 _) (pts_to a p2 x) let gather #_ #_ a #x1 p1 #x2 p2 = rewrite (pts_to a p1 _) (H.pts_to a p1 (seq_map raise x1)); rewrite (pts_to a p2 _) (H.pts_to a p2 (seq_map raise x2)); H.gather a p1 p2; rewrite (H.pts_to a _ _) (pts_to _ _ _) let index #_ #p a #s i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise s)); let res = H.index a i in rewrite (H.pts_to _ _ _) (pts_to _ _ _); return (lower res) let upd #_ a #s i v = rewrite (pts_to a _ _) (H.pts_to a P.full_perm (seq_map raise s)); H.upd a i (raise v); assert (seq_map raise (Seq.upd s (US.v i) v) `Seq.equal` Seq.upd (seq_map raise s) (US.v i) (raise v)); rewrite (H.pts_to _ _ _) (pts_to _ _ _) let ghost_join #_ #_ #x1 #x2 #p a1 a2 h = rewrite (pts_to a1 _ _) (H.pts_to a1 p (seq_map raise x1)); rewrite (pts_to a2 _ _) (H.pts_to a2 p (seq_map raise x2)); H.ghost_join a1 a2 h; assert (seq_map raise (x1 `Seq.append` x2) `Seq.equal` (seq_map raise x1 `Seq.append` seq_map raise x2)); rewrite (H.pts_to _ _ _) (H.pts_to (merge a1 a2) p (seq_map raise (x1 `Seq.append` x2))); rewrite (H.pts_to _ _ _) (pts_to (merge a1 a2) _ _) let ptr_shift p off = H.ptr_shift p off let ghost_split #_ #_ #x #p a i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); let _ = H.ghost_split a i in //H.ghost_split a i; assert (seq_map raise (Seq.slice x 0 (US.v i)) `Seq.equal` Seq.slice (seq_map raise x) 0 (US.v i)); rewrite (H.pts_to (H.split_l a i) _ _) (H.pts_to (split_l a i) p (seq_map raise (Seq.slice x 0 (US.v i)))); rewrite (H.pts_to (split_l a i) _ _) (pts_to (split_l a i) _ _); assert (seq_map raise (Seq.slice x (US.v i) (Seq.length x)) `Seq.equal` Seq.slice (seq_map raise x) (US.v i) (Seq.length (seq_map raise x))); Seq.lemma_split x (US.v i); rewrite (H.pts_to (H.split_r a i) _ _) (H.pts_to (split_r a i) p (seq_map raise (Seq.slice x (US.v i) (Seq.length x)))); rewrite (H.pts_to (split_r a i) _ _) (pts_to (split_r a i) _ _) let memcpy a0 a1 l = H.memcpy a0 a1 l //////////////////////////////////////////////////////////////////////////////// // compare //////////////////////////////////////////////////////////////////////////////// module R = Steel.ST.Reference #push-options "--fuel 0 --ifuel 1 --z3rlimit_factor 2" let equal_up_to #t (s0: Seq.seq t) (s1: Seq.seq t) (v : option US.t) : prop = Seq.length s0 = Seq.length s1 /\ (match v with | None -> Ghost.reveal s0 =!= Ghost.reveal s1 | Some v -> US.v v <= Seq.length s0 /\ Seq.slice s0 0 (US.v v) `Seq.equal` Seq.slice s1 0 (US.v v)) let within_bounds (x:option US.t) (l:US.t) (b:Ghost.erased bool) : prop = if b then Some? x /\ US.(Some?.v x <^ l) else None? x \/ US.(Some?.v x >=^ l) let compare_inv (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (s0: Seq.seq t) (s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (b: bool) = pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (x:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l b)) let elim_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (b: bool) : STGhostT (Ghost.erased (option US.t)) o (compare_inv a0 a1 s0 s1 l ctr b) (fun x -> let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l b)) = let open US in assert_spinoff ((compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr b) == (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l b)))); rewrite (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr b) (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l b))); let _v = elim_exists () in _v let intro_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (x: Ghost.erased (option US.t)) (b:bool { within_bounds x l b }) : STGhostT unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x)) (fun _ -> compare_inv a0 a1 s0 s1 l ctr (Ghost.hide b)) = let open US in intro_pure (within_bounds x l (Ghost.hide b)); intro_exists_erased x (fun (x:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l (Ghost.hide b))); assert_norm ((compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) == (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l (Ghost.hide b))))); rewrite (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l (Ghost.hide b)))) (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) let intro_exists_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (x: Ghost.erased (option US.t)) : STGhostT unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) = let b : bool = match Ghost.reveal x with | None -> false | Some x -> US.(x <^ l) in assert (within_bounds x l b); intro_compare_inv #_ #_ #p0 #p1 a0 a1 #s0 #s1 l ctr x b; intro_exists _ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr) let extend_equal_up_to_lemma (#t:Type0) (s0:Seq.seq t) (s1:Seq.seq t) (i:nat{ i < Seq.length s0 /\ Seq.length s0 == Seq.length s1 }) : Lemma (requires Seq.equal (Seq.slice s0 0 i) (Seq.slice s1 0 i) /\ Seq.index s0 i == Seq.index s1 i) (ensures Seq.equal (Seq.slice s0 0 (i + 1)) (Seq.slice s1 0 (i + 1))) = assert (forall k. k < i ==> Seq.index s0 k == Seq.index (Seq.slice s0 0 i) k /\ Seq.index s1 k == Seq.index (Seq.slice s1 0 i) k) let extend_equal_up_to (#o:_) (#t:Type0) (#s0:Seq.seq t) (#s1:Seq.seq t) (len:US.t) (i:US.t{ Seq.length s0 == Seq.length s1 /\ US.(i <^ len) /\ US.v len == Seq.length s0 } ) : STGhost unit o (pure (equal_up_to s0 s1 (Some i))) (fun _ -> pure (equal_up_to s0 s1 (Some US.(i +^ 1sz)))) (requires Seq.index s0 (US.v i) == Seq.index s1 (US.v i)) (ensures fun _ -> True) = elim_pure _; extend_equal_up_to_lemma s0 s1 (US.v i); intro_pure (equal_up_to s0 s1 (Some US.(i +^ 1sz))) let extend_equal_up_to_neg (#o:_) (#t:Type0) (#s0:Seq.seq t) (#s1:Seq.seq t) (len:US.t) (i:US.t{ Seq.length s0 == Seq.length s1 /\ US.(i <^ len) /\ US.v len == Seq.length s0 } ) : STGhost unit o (pure (equal_up_to s0 s1 (Some i))) (fun _ -> pure (equal_up_to s0 s1 None)) (requires Seq.index s0 (US.v i) =!= Seq.index s1 (US.v i)) (ensures fun _ -> True) = elim_pure _; intro_pure _ let init_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) : STGhost unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm (Some 0sz)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) (requires ( length a0 > 0 /\ length a0 == length a1 /\ US.v l == length a0 )) (ensures (fun _ -> True)) = pts_to_length a0 _; pts_to_length a1 _; intro_pure (equal_up_to s0 s1 (Ghost.hide (Some 0sz))); rewrite (R.pts_to ctr Steel.FractionalPermission.full_perm (Some 0sz)) (R.pts_to ctr Steel.FractionalPermission.full_perm (Ghost.hide (Some 0sz))); intro_exists_compare_inv a0 a1 l ctr (Ghost.hide (Some 0sz)) let compare_pts (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Ghost.erased (Seq.seq t)) (#s1: Ghost.erased (Seq.seq t)) (l:US.t) : ST bool (pts_to a0 p0 s0 `star` pts_to a1 p1 s1) (fun _ -> pts_to a0 p0 s0 `star` pts_to a1 p1 s1) (requires length a0 > 0 /\ length a0 == length a1 /\ US.v l == length a0 ) (ensures fun b -> b = (Ghost.reveal s0 = Ghost.reveal s1)) = pts_to_length a0 _; pts_to_length a1 _; let ctr = R.alloc (Some 0sz) in let cond () : STT bool (exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) (fun b -> compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) = let _b = elim_exists () in let _ = elim_compare_inv _ _ _ _ _ in let x = R.read ctr in elim_pure (within_bounds _ _ _); match x with | None -> intro_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr _ false; return false | Some x -> let res = US.(x <^ l) in intro_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr _ res; return res in let body () : STT unit (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide true)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) = let _i = elim_compare_inv _ _ _ _ _ in elim_pure (within_bounds _ _ _); let Some i = R.read ctr in assert_spinoff ((pure (equal_up_to s0 s1 _i)) == (pure (equal_up_to s0 s1 (Some i)))); rewrite (pure (equal_up_to s0 s1 _i)) (pure (equal_up_to s0 s1 (Some i))); let v0 = index a0 i in let v1 = index a1 i in if v0 = v1 then ( R.write ctr (Some US.(i +^ 1sz)); extend_equal_up_to l i; intro_exists_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr (Ghost.hide (Some (US.(i +^ 1sz)))) ) else ( R.write ctr None; extend_equal_up_to_neg l i; intro_exists_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr (Ghost.hide None) ) in init_compare_inv a0 a1 l ctr; Steel.ST.Loops.while_loop (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr) cond body; let _ = elim_compare_inv _ _ _ _ _ in elim_pure (equal_up_to _ _ _); let v = R.read ctr in R.free ctr; elim_pure (within_bounds _ _ _); match v with | None -> return false | Some _ -> return true let compare #t #p0 #p1 a0 a1 #s0 #s1 l = pts_to_length a0 _; pts_to_length a1 _; if l = 0sz then ( assert (Seq.equal s0 s1); return true ) else ( compare_pts a0 a1 l ) #pop-options let intro_fits_u32 () = H.intro_fits_u32 () let intro_fits_u64 () = H.intro_fits_u64 () let intro_fits_ptrdiff32 () = H.intro_fits_ptrdiff32 () let intro_fits_ptrdiff64 () = H.intro_fits_ptrdiff64 () let ptrdiff #_ #p0 #p1 #s0 #s1 a0 a1 = rewrite (pts_to a0 _ _) (H.pts_to a0 p0 (seq_map raise s0)); rewrite (pts_to a1 _ _) (H.pts_to a1 p1 (seq_map raise s1)); let res = H.ptrdiff a0 a1 in rewrite (H.pts_to a1 _ _) (pts_to a1 _ _); rewrite (H.pts_to a0 _ _) (pts_to a0 _ _); return res let array_slice (#elt: Type0) (a: array elt) (i j: nat) (sq: squash (i <= j /\ j <= length a)) : Ghost (array elt) (requires True) (ensures (fun a' -> length a' == j - i)) = length_fits a; split_l (split_r a (US.uint_to_t i)) (US.uint_to_t (j - i))
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.Reference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.ST.Array.array elt -> i: Prims.nat -> j: Prims.nat -> p: Steel.FractionalPermission.perm -> s: FStar.Seq.Base.seq elt -> sq: Prims.squash (i <= j /\ j <= Steel.ST.Array.length a) -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.Array.array", "Prims.nat", "Steel.FractionalPermission.perm", "FStar.Seq.Base.seq", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Steel.ST.Array.length", "Steel.ST.Array.pts_to", "Steel.ST.Array.array_slice", "Steel.Effect.Common.vprop" ]
[]
false
false
false
false
false
let pts_to_range_body (#elt: Type0) (a: array elt) (i j: nat) (p: P.perm) (s: Seq.seq elt) (sq: squash (i <= j /\ j <= length a)) : Tot vprop =
pts_to (array_slice a i j sq) p s
false
Steel.ST.Array.fst
Steel.ST.Array.pts_to_range
val pts_to_range (#elt: Type0) (a: array elt) (i j: nat) (p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop
val pts_to_range (#elt: Type0) (a: array elt) (i j: nat) (p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop
let pts_to_range (#elt: Type0) (a: array elt) (i j: nat) (p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop = exists_ (pts_to_range_body a i j p s)
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 39, "end_line": 583, "start_col": 0, "start_line": 578 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2 let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt) let length_fits a = H.length_fits a let pts_to a p s = H.pts_to a p (seq_map raise s) let pts_to_length a s = H.pts_to_length a _ let h_array_eq' (#t: Type u#1) (a1 a2: H.array t) : Lemma (requires ( dfst a1 == dfst a2 /\ (Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2) )) (ensures ( a1 == a2 )) = () let pts_to_not_null #_ #t #p a s = let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in assert (a =!= H.null #(raise_t t)); Classical.move_requires (h_array_eq' a) (H.null #(raise_t t)); noop () let pts_to_inj a p1 s1 p2 s2 = H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2) /// Non-selector operations. let malloc x n = let res = H.malloc (raise x) n in assert (seq_map raise (Seq.create (US.v n) x) `Seq.equal` Seq.create (US.v n) (raise x)); rewrite (H.pts_to res _ _) (pts_to res _ _); return res let free #_ x = let s = elim_exists () in rewrite (pts_to x _ _) (H.pts_to x P.full_perm (seq_map raise s)); H.free x let share #_ #_ #x a p p1 p2 = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); H.share a p p1 p2; rewrite (H.pts_to a p1 _) (pts_to a p1 x); rewrite (H.pts_to a p2 _) (pts_to a p2 x) let gather #_ #_ a #x1 p1 #x2 p2 = rewrite (pts_to a p1 _) (H.pts_to a p1 (seq_map raise x1)); rewrite (pts_to a p2 _) (H.pts_to a p2 (seq_map raise x2)); H.gather a p1 p2; rewrite (H.pts_to a _ _) (pts_to _ _ _) let index #_ #p a #s i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise s)); let res = H.index a i in rewrite (H.pts_to _ _ _) (pts_to _ _ _); return (lower res) let upd #_ a #s i v = rewrite (pts_to a _ _) (H.pts_to a P.full_perm (seq_map raise s)); H.upd a i (raise v); assert (seq_map raise (Seq.upd s (US.v i) v) `Seq.equal` Seq.upd (seq_map raise s) (US.v i) (raise v)); rewrite (H.pts_to _ _ _) (pts_to _ _ _) let ghost_join #_ #_ #x1 #x2 #p a1 a2 h = rewrite (pts_to a1 _ _) (H.pts_to a1 p (seq_map raise x1)); rewrite (pts_to a2 _ _) (H.pts_to a2 p (seq_map raise x2)); H.ghost_join a1 a2 h; assert (seq_map raise (x1 `Seq.append` x2) `Seq.equal` (seq_map raise x1 `Seq.append` seq_map raise x2)); rewrite (H.pts_to _ _ _) (H.pts_to (merge a1 a2) p (seq_map raise (x1 `Seq.append` x2))); rewrite (H.pts_to _ _ _) (pts_to (merge a1 a2) _ _) let ptr_shift p off = H.ptr_shift p off let ghost_split #_ #_ #x #p a i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); let _ = H.ghost_split a i in //H.ghost_split a i; assert (seq_map raise (Seq.slice x 0 (US.v i)) `Seq.equal` Seq.slice (seq_map raise x) 0 (US.v i)); rewrite (H.pts_to (H.split_l a i) _ _) (H.pts_to (split_l a i) p (seq_map raise (Seq.slice x 0 (US.v i)))); rewrite (H.pts_to (split_l a i) _ _) (pts_to (split_l a i) _ _); assert (seq_map raise (Seq.slice x (US.v i) (Seq.length x)) `Seq.equal` Seq.slice (seq_map raise x) (US.v i) (Seq.length (seq_map raise x))); Seq.lemma_split x (US.v i); rewrite (H.pts_to (H.split_r a i) _ _) (H.pts_to (split_r a i) p (seq_map raise (Seq.slice x (US.v i) (Seq.length x)))); rewrite (H.pts_to (split_r a i) _ _) (pts_to (split_r a i) _ _) let memcpy a0 a1 l = H.memcpy a0 a1 l //////////////////////////////////////////////////////////////////////////////// // compare //////////////////////////////////////////////////////////////////////////////// module R = Steel.ST.Reference #push-options "--fuel 0 --ifuel 1 --z3rlimit_factor 2" let equal_up_to #t (s0: Seq.seq t) (s1: Seq.seq t) (v : option US.t) : prop = Seq.length s0 = Seq.length s1 /\ (match v with | None -> Ghost.reveal s0 =!= Ghost.reveal s1 | Some v -> US.v v <= Seq.length s0 /\ Seq.slice s0 0 (US.v v) `Seq.equal` Seq.slice s1 0 (US.v v)) let within_bounds (x:option US.t) (l:US.t) (b:Ghost.erased bool) : prop = if b then Some? x /\ US.(Some?.v x <^ l) else None? x \/ US.(Some?.v x >=^ l) let compare_inv (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (s0: Seq.seq t) (s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (b: bool) = pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (x:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l b)) let elim_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (b: bool) : STGhostT (Ghost.erased (option US.t)) o (compare_inv a0 a1 s0 s1 l ctr b) (fun x -> let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l b)) = let open US in assert_spinoff ((compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr b) == (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l b)))); rewrite (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr b) (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l b))); let _v = elim_exists () in _v let intro_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (x: Ghost.erased (option US.t)) (b:bool { within_bounds x l b }) : STGhostT unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x)) (fun _ -> compare_inv a0 a1 s0 s1 l ctr (Ghost.hide b)) = let open US in intro_pure (within_bounds x l (Ghost.hide b)); intro_exists_erased x (fun (x:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l (Ghost.hide b))); assert_norm ((compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) == (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l (Ghost.hide b))))); rewrite (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l (Ghost.hide b)))) (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) let intro_exists_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (x: Ghost.erased (option US.t)) : STGhostT unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) = let b : bool = match Ghost.reveal x with | None -> false | Some x -> US.(x <^ l) in assert (within_bounds x l b); intro_compare_inv #_ #_ #p0 #p1 a0 a1 #s0 #s1 l ctr x b; intro_exists _ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr) let extend_equal_up_to_lemma (#t:Type0) (s0:Seq.seq t) (s1:Seq.seq t) (i:nat{ i < Seq.length s0 /\ Seq.length s0 == Seq.length s1 }) : Lemma (requires Seq.equal (Seq.slice s0 0 i) (Seq.slice s1 0 i) /\ Seq.index s0 i == Seq.index s1 i) (ensures Seq.equal (Seq.slice s0 0 (i + 1)) (Seq.slice s1 0 (i + 1))) = assert (forall k. k < i ==> Seq.index s0 k == Seq.index (Seq.slice s0 0 i) k /\ Seq.index s1 k == Seq.index (Seq.slice s1 0 i) k) let extend_equal_up_to (#o:_) (#t:Type0) (#s0:Seq.seq t) (#s1:Seq.seq t) (len:US.t) (i:US.t{ Seq.length s0 == Seq.length s1 /\ US.(i <^ len) /\ US.v len == Seq.length s0 } ) : STGhost unit o (pure (equal_up_to s0 s1 (Some i))) (fun _ -> pure (equal_up_to s0 s1 (Some US.(i +^ 1sz)))) (requires Seq.index s0 (US.v i) == Seq.index s1 (US.v i)) (ensures fun _ -> True) = elim_pure _; extend_equal_up_to_lemma s0 s1 (US.v i); intro_pure (equal_up_to s0 s1 (Some US.(i +^ 1sz))) let extend_equal_up_to_neg (#o:_) (#t:Type0) (#s0:Seq.seq t) (#s1:Seq.seq t) (len:US.t) (i:US.t{ Seq.length s0 == Seq.length s1 /\ US.(i <^ len) /\ US.v len == Seq.length s0 } ) : STGhost unit o (pure (equal_up_to s0 s1 (Some i))) (fun _ -> pure (equal_up_to s0 s1 None)) (requires Seq.index s0 (US.v i) =!= Seq.index s1 (US.v i)) (ensures fun _ -> True) = elim_pure _; intro_pure _ let init_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) : STGhost unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm (Some 0sz)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) (requires ( length a0 > 0 /\ length a0 == length a1 /\ US.v l == length a0 )) (ensures (fun _ -> True)) = pts_to_length a0 _; pts_to_length a1 _; intro_pure (equal_up_to s0 s1 (Ghost.hide (Some 0sz))); rewrite (R.pts_to ctr Steel.FractionalPermission.full_perm (Some 0sz)) (R.pts_to ctr Steel.FractionalPermission.full_perm (Ghost.hide (Some 0sz))); intro_exists_compare_inv a0 a1 l ctr (Ghost.hide (Some 0sz)) let compare_pts (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Ghost.erased (Seq.seq t)) (#s1: Ghost.erased (Seq.seq t)) (l:US.t) : ST bool (pts_to a0 p0 s0 `star` pts_to a1 p1 s1) (fun _ -> pts_to a0 p0 s0 `star` pts_to a1 p1 s1) (requires length a0 > 0 /\ length a0 == length a1 /\ US.v l == length a0 ) (ensures fun b -> b = (Ghost.reveal s0 = Ghost.reveal s1)) = pts_to_length a0 _; pts_to_length a1 _; let ctr = R.alloc (Some 0sz) in let cond () : STT bool (exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) (fun b -> compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) = let _b = elim_exists () in let _ = elim_compare_inv _ _ _ _ _ in let x = R.read ctr in elim_pure (within_bounds _ _ _); match x with | None -> intro_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr _ false; return false | Some x -> let res = US.(x <^ l) in intro_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr _ res; return res in let body () : STT unit (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide true)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) = let _i = elim_compare_inv _ _ _ _ _ in elim_pure (within_bounds _ _ _); let Some i = R.read ctr in assert_spinoff ((pure (equal_up_to s0 s1 _i)) == (pure (equal_up_to s0 s1 (Some i)))); rewrite (pure (equal_up_to s0 s1 _i)) (pure (equal_up_to s0 s1 (Some i))); let v0 = index a0 i in let v1 = index a1 i in if v0 = v1 then ( R.write ctr (Some US.(i +^ 1sz)); extend_equal_up_to l i; intro_exists_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr (Ghost.hide (Some (US.(i +^ 1sz)))) ) else ( R.write ctr None; extend_equal_up_to_neg l i; intro_exists_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr (Ghost.hide None) ) in init_compare_inv a0 a1 l ctr; Steel.ST.Loops.while_loop (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr) cond body; let _ = elim_compare_inv _ _ _ _ _ in elim_pure (equal_up_to _ _ _); let v = R.read ctr in R.free ctr; elim_pure (within_bounds _ _ _); match v with | None -> return false | Some _ -> return true let compare #t #p0 #p1 a0 a1 #s0 #s1 l = pts_to_length a0 _; pts_to_length a1 _; if l = 0sz then ( assert (Seq.equal s0 s1); return true ) else ( compare_pts a0 a1 l ) #pop-options let intro_fits_u32 () = H.intro_fits_u32 () let intro_fits_u64 () = H.intro_fits_u64 () let intro_fits_ptrdiff32 () = H.intro_fits_ptrdiff32 () let intro_fits_ptrdiff64 () = H.intro_fits_ptrdiff64 () let ptrdiff #_ #p0 #p1 #s0 #s1 a0 a1 = rewrite (pts_to a0 _ _) (H.pts_to a0 p0 (seq_map raise s0)); rewrite (pts_to a1 _ _) (H.pts_to a1 p1 (seq_map raise s1)); let res = H.ptrdiff a0 a1 in rewrite (H.pts_to a1 _ _) (pts_to a1 _ _); rewrite (H.pts_to a0 _ _) (pts_to a0 _ _); return res let array_slice (#elt: Type0) (a: array elt) (i j: nat) (sq: squash (i <= j /\ j <= length a)) : Ghost (array elt) (requires True) (ensures (fun a' -> length a' == j - i)) = length_fits a; split_l (split_r a (US.uint_to_t i)) (US.uint_to_t (j - i)) [@@__reduce__] let pts_to_range_body (#elt: Type0) (a: array elt) (i j: nat) (p: P.perm) (s: Seq.seq elt) (sq: squash (i <= j /\ j <= length a)) : Tot vprop = pts_to (array_slice a i j sq) p s
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.Reference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.ST.Array.array elt -> i: Prims.nat -> j: Prims.nat -> p: Steel.FractionalPermission.perm -> s: FStar.Seq.Base.seq elt -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.Array.array", "Prims.nat", "Steel.FractionalPermission.perm", "FStar.Seq.Base.seq", "Steel.ST.Util.exists_", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Steel.ST.Array.length", "Steel.ST.Array.pts_to_range_body", "Steel.Effect.Common.vprop" ]
[]
false
false
false
true
false
let pts_to_range (#elt: Type0) (a: array elt) (i j: nat) (p: P.perm) ([@@@ smt_fallback]s: Seq.seq elt) : Tot vprop =
exists_ (pts_to_range_body a i j p s)
false
Steel.ST.Array.fst
Steel.ST.Array.ptr_base_offset_inj
val ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 ))
val ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 ))
let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 59, "end_line": 92, "start_col": 0, "start_line": 92 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p1: Steel.ST.Array.ptr elt -> p2: Steel.ST.Array.ptr elt -> FStar.Pervasives.Lemma (requires Steel.ST.Array.base p1 == Steel.ST.Array.base p2 /\ Steel.ST.Array.offset p1 == Steel.ST.Array.offset p2) (ensures p1 == p2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.ST.Array.ptr", "Steel.ST.HigherArray.ptr_base_offset_inj", "Steel.ST.Array.raise_t", "Prims.unit" ]
[]
true
false
true
false
false
let ptr_base_offset_inj p1 p2 =
H.ptr_base_offset_inj p1 p2
false
Steel.ST.Array.fst
Steel.ST.Array.is_null_ptr
val is_null_ptr (#elt: Type0) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt))
val is_null_ptr (#elt: Type0) (p: ptr elt) : Pure bool (requires True) (ensures (fun res -> res == true <==> p == null_ptr elt))
let is_null_ptr p = H.is_null_ptr p
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 89, "start_col": 0, "start_line": 89 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Steel.ST.Array.ptr elt -> Prims.Pure Prims.bool
Prims.Pure
[]
[]
[ "Steel.ST.Array.ptr", "Steel.ST.HigherArray.is_null_ptr", "Steel.ST.Array.raise_t", "Prims.bool" ]
[]
false
false
false
false
false
let is_null_ptr p =
H.is_null_ptr p
false
Steel.ST.Array.fst
Steel.ST.Array.seq_map
val seq_map (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i. {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)))) (decreases (Seq.length s))
val seq_map (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i. {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)))) (decreases (Seq.length s))
let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s)))
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 78, "end_line": 57, "start_col": 0, "start_line": 43 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors.
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: t -> Prims.GTot t') -> s: FStar.Seq.Base.seq t -> Prims.Ghost (FStar.Seq.Base.seq t')
Prims.Ghost
[ "" ]
[]
[ "FStar.Seq.Base.seq", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.Seq.Base.empty", "Prims.bool", "FStar.Seq.Base.cons", "FStar.Seq.Base.index", "Steel.ST.Array.seq_map", "FStar.Seq.Base.slice", "Prims.l_True", "Prims.l_and", "Prims.eq2", "Prims.nat", "Prims.l_Forall", "Prims.b2t", "Prims.op_LessThan" ]
[ "recursion" ]
false
false
false
false
false
let rec seq_map (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i. {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)))) (decreases (Seq.length s)) =
if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s)))
false
Steel.ST.Array.fst
Steel.ST.Array.offset
val offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p)))
val offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p)))
let offset p = H.offset p
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 91, "start_col": 0, "start_line": 91 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Steel.ST.Array.ptr elt -> Prims.Ghost Prims.nat
Prims.Ghost
[]
[]
[ "Steel.ST.Array.ptr", "Steel.ST.HigherArray.offset", "Steel.ST.Array.raise_t", "Prims.nat" ]
[]
false
false
false
false
false
let offset p =
H.offset p
false
Hacl.Spec.P256.PrecompTable.fst
Hacl.Spec.P256.PrecompTable.proj_point_to_list_sub
val proj_point_to_list_sub: p:S.proj_point -> Lemma (let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in let p_list = FL.(px_list @ py_list @ pz_list) in let p_lseq = Seq.seq_of_list p_list <: lseq uint64 12 in let px_lseq = Seq.seq_of_list px_list <: lseq uint64 4 in let py_lseq = Seq.seq_of_list py_list <: lseq uint64 4 in let pz_lseq = Seq.seq_of_list pz_list <: lseq uint64 4 in sub p_lseq 0 4 == px_lseq /\ sub p_lseq 4 4 == py_lseq /\ sub p_lseq 8 4 == pz_lseq)
val proj_point_to_list_sub: p:S.proj_point -> Lemma (let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in let p_list = FL.(px_list @ py_list @ pz_list) in let p_lseq = Seq.seq_of_list p_list <: lseq uint64 12 in let px_lseq = Seq.seq_of_list px_list <: lseq uint64 4 in let py_lseq = Seq.seq_of_list py_list <: lseq uint64 4 in let pz_lseq = Seq.seq_of_list pz_list <: lseq uint64 4 in sub p_lseq 0 4 == px_lseq /\ sub p_lseq 4 4 == py_lseq /\ sub p_lseq 8 4 == pz_lseq)
let proj_point_to_list_sub p = let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in FL.append_assoc px_list py_list pz_list; SPT.seq_of_list_append_lemma px_list py_list; SPT.seq_of_list_append_lemma FL.(px_list @ py_list) pz_list
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 82, "start_col": 0, "start_line": 71 }
module Hacl.Spec.P256.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Impl.P256.Point module S = Spec.P256 module SM = Hacl.Spec.P256.Montgomery module BD = Hacl.Spec.Bignum.Definitions module FL = FStar.List.Tot module SPT = Hacl.Spec.PrecompBaseTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let create4_lseq (x0 x1 x2 x3:uint64) : lseq uint64 4 = let l = [x0; x1; x2; x3] in assert_norm (FL.length l = 4); Seq.seq_of_list l val create4_lemma (x0 x1 x2 x3:uint64) : Lemma (let s = create4_lseq x0 x1 x2 x3 in s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3) let create4_lemma x0 x1 x2 x3 = Seq.elim_of_list [x0; x1; x2; x3] //----------------------------------- noextract let list_as_felem4 (f:felem_list) : lseq uint64 4 = Seq.seq_of_list f <: lseq uint64 4 val felem_to_list_lemma_eval: x:S.felem -> Lemma (BD.bn_v (list_as_felem4 (felem_to_list x)) == x) let felem_to_list_lemma_eval x = let x0 = x % pow2 64 in let x1 = x / pow2 64 % pow2 64 in let x2 = x / pow2 128 % pow2 64 in let x3 = x / pow2 192 % pow2 64 in let bn_x = list_as_felem4 (felem_to_list x) in create4_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3); assert (v bn_x.[0] == x0 /\ v bn_x.[1] == x1 /\ v bn_x.[2] == x2 /\ v bn_x.[3] == x3); Hacl.Impl.P256.Bignum.bn_v_is_as_nat bn_x; assert (BD.bn_v bn_x = x0 + x1 * pow2 64 + x2 * pow2 128 + x3 * pow2 192); Hacl.Spec.PrecompBaseTable256.lemma_decompose_nat256_as_four_u64 x //-------------------------------------------- val proj_point_to_list_sub: p:S.proj_point -> Lemma (let (px, py, pz) = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in let p_list = FL.(px_list @ py_list @ pz_list) in let p_lseq = Seq.seq_of_list p_list <: lseq uint64 12 in let px_lseq = Seq.seq_of_list px_list <: lseq uint64 4 in let py_lseq = Seq.seq_of_list py_list <: lseq uint64 4 in let pz_lseq = Seq.seq_of_list pz_list <: lseq uint64 4 in sub p_lseq 0 4 == px_lseq /\ sub p_lseq 4 4 == py_lseq /\ sub p_lseq 8 4 == pz_lseq)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "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.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.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
p: Spec.P256.PointOps.proj_point -> FStar.Pervasives.Lemma (ensures (let _ = p in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ px py pz = _ in let pxM = Hacl.Spec.P256.Montgomery.to_mont px in let pyM = Hacl.Spec.P256.Montgomery.to_mont py in let pzM = Hacl.Spec.P256.Montgomery.to_mont pz in let px_list = Hacl.Spec.P256.PrecompTable.felem_to_list pxM in let py_list = Hacl.Spec.P256.PrecompTable.felem_to_list pyM in let pz_list = Hacl.Spec.P256.PrecompTable.felem_to_list pzM in let p_list = px_list @ py_list @ pz_list in let p_lseq = FStar.Seq.Base.seq_of_list p_list <: Lib.Sequence.lseq Lib.IntTypes.uint64 12 in let px_lseq = FStar.Seq.Base.seq_of_list px_list <: Lib.Sequence.lseq Lib.IntTypes.uint64 4 in let py_lseq = FStar.Seq.Base.seq_of_list py_list <: Lib.Sequence.lseq Lib.IntTypes.uint64 4 in let pz_lseq = FStar.Seq.Base.seq_of_list pz_list <: Lib.Sequence.lseq Lib.IntTypes.uint64 4 in Lib.Sequence.sub p_lseq 0 4 == px_lseq /\ Lib.Sequence.sub p_lseq 4 4 == py_lseq /\ Lib.Sequence.sub p_lseq 8 4 == pz_lseq) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.proj_point", "Prims.nat", "Hacl.Spec.PrecompBaseTable.seq_of_list_append_lemma", "Lib.IntTypes.uint64", "FStar.List.Tot.Base.op_At", "Prims.unit", "FStar.List.Tot.Properties.append_assoc", "Hacl.Spec.P256.PrecompTable.felem_list", "Hacl.Spec.P256.PrecompTable.felem_to_list", "Spec.P256.PointOps.felem", "Hacl.Spec.P256.Montgomery.to_mont" ]
[]
false
false
true
false
false
let proj_point_to_list_sub p =
let px, py, pz = p in let pxM = SM.to_mont px in let pyM = SM.to_mont py in let pzM = SM.to_mont pz in let px_list = felem_to_list pxM in let py_list = felem_to_list pyM in let pz_list = felem_to_list pzM in FL.append_assoc px_list py_list pz_list; SPT.seq_of_list_append_lemma px_list py_list; SPT.seq_of_list_append_lemma FL.(px_list @ py_list) pz_list
false
Steel.ST.Array.fst
Steel.ST.Array.pts_to_inj
val pts_to_inj (#elt: Type0) (a: array elt) (p1: P.perm) (s1: Seq.seq elt) (p2: P.perm) (s2: Seq.seq elt) (m: mem) : Lemma (requires ( interp (hp_of (pts_to a p1 s1)) m /\ interp (hp_of (pts_to a p2 s2)) m )) (ensures ( s1 == s2 ))
val pts_to_inj (#elt: Type0) (a: array elt) (p1: P.perm) (s1: Seq.seq elt) (p2: P.perm) (s2: Seq.seq elt) (m: mem) : Lemma (requires ( interp (hp_of (pts_to a p1 s1)) m /\ interp (hp_of (pts_to a p2 s2)) m )) (ensures ( s1 == s2 ))
let pts_to_inj a p1 s1 p2 s2 = H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2)
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 60, "end_line": 122, "start_col": 0, "start_line": 121 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2 let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt) let length_fits a = H.length_fits a let pts_to a p s = H.pts_to a p (seq_map raise s) let pts_to_length a s = H.pts_to_length a _ let h_array_eq' (#t: Type u#1) (a1 a2: H.array t) : Lemma (requires ( dfst a1 == dfst a2 /\ (Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2) )) (ensures ( a1 == a2 )) = () let pts_to_not_null #_ #t #p a s = let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in assert (a =!= H.null #(raise_t t)); Classical.move_requires (h_array_eq' a) (H.null #(raise_t t)); noop ()
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.ST.Array.array elt -> p1: Steel.FractionalPermission.perm -> s1: FStar.Seq.Base.seq elt -> p2: Steel.FractionalPermission.perm -> s2: FStar.Seq.Base.seq elt -> m: Steel.Memory.mem -> FStar.Pervasives.Lemma (requires Steel.Memory.interp (Steel.Effect.Common.hp_of (Steel.ST.Array.pts_to a p1 s1)) m /\ Steel.Memory.interp (Steel.Effect.Common.hp_of (Steel.ST.Array.pts_to a p2 s2)) m) (ensures s1 == s2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.ST.Array.array", "Steel.FractionalPermission.perm", "FStar.Seq.Base.seq", "Steel.ST.HigherArray.pts_to_inj", "Steel.ST.Array.raise_t", "Steel.ST.Array.seq_map", "Steel.ST.Array.raise", "Steel.Memory.mem", "Prims.unit", "Prims.l_and", "Steel.Memory.interp", "Steel.Effect.Common.hp_of", "Steel.ST.Array.pts_to", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let pts_to_inj a p1 s1 p2 s2 =
H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2)
false
Steel.ST.Array.fst
Steel.ST.Array.length_fits
val length_fits (#elt: Type) (a: array elt) : Lemma (US.fits (length a))
val length_fits (#elt: Type) (a: array elt) : Lemma (US.fits (length a))
let length_fits a = H.length_fits a
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 95, "start_col": 0, "start_line": 95 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.ST.Array.array elt -> FStar.Pervasives.Lemma (ensures FStar.SizeT.fits (Steel.ST.Array.length a))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.ST.Array.array", "Steel.ST.HigherArray.length_fits", "Steel.ST.Array.raise_t", "Prims.unit" ]
[]
true
false
true
false
false
let length_fits a =
H.length_fits a
false
Steel.ST.Array.fst
Steel.ST.Array.base_len_null_ptr
val base_len_null_ptr (elt: Type0) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))]
val base_len_null_ptr (elt: Type0) : Lemma (base_len (base (null_ptr elt)) == 0) [SMTPat (base_len (base (null_ptr elt)))]
let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt)
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 61, "end_line": 94, "start_col": 0, "start_line": 94 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
elt: Type0 -> FStar.Pervasives.Lemma (ensures Steel.ST.Array.base_len (Steel.ST.Array.base (Steel.ST.Array.null_ptr elt)) == 0) [SMTPat (Steel.ST.Array.base_len (Steel.ST.Array.base (Steel.ST.Array.null_ptr elt)))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.ST.HigherArray.base_len_null_ptr", "Steel.ST.Array.raise_t", "Prims.unit" ]
[]
true
false
true
false
false
let base_len_null_ptr elt =
H.base_len_null_ptr (raise_t elt)
false
Steel.ST.Reference.fst
Steel.ST.Reference._alloca
val _alloca (#a: Type) (x: a) : ST (ref a) emp (fun r -> pts_to r full_perm x) (requires True) (ensures fun r -> not (is_null r))
val _alloca (#a: Type) (x: a) : ST (ref a) emp (fun r -> pts_to r full_perm x) (requires True) (ensures fun r -> not (is_null r))
let _alloca (#a:Type) (x:a) : ST (ref a) emp (fun r -> pts_to r full_perm x) (requires True) (ensures fun r -> not (is_null r)) = alloc x
{ "file_name": "lib/steel/Steel.ST.Reference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 9, "end_line": 118, "start_col": 0, "start_line": 112 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Reference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference let ref (a:Type0) : Type0 = R.ref a let null (#a:Type0) : ref a = R.null #a let is_null (#a:Type0) (r:ref a) : b:bool{b <==> r == null} = R.is_null r let pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@smt_fallback] v:a) : vprop = R.pts_to r p v let pts_to_injective_eq (#a: Type) (#opened:inames) (#p0 #p1:perm) (#v0 #v1:a) (r: ref a) : STGhost unit opened (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.pts_to_injective_eq #a #opened #p0 #p1 #(hide v0) #(hide v1) r) let pts_to_not_null #a #opened #p #v r = extract_fact #opened (pts_to r p v) (r =!= null) (R.pts_to_not_null r p v); () let pts_to_perm r = coerce_ghost (fun _ -> R.pts_to_perm r) let alloc (#a:Type) (x:a) : ST (ref a) emp (fun r -> pts_to r full_perm x) (requires True) (ensures fun r -> not (is_null r)) = let r = coerce_steel (fun _ -> R.alloc_pt x) in r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) : ST a (pts_to r p v) (fun _ -> pts_to r p v) (requires True) (ensures fun x -> x == Ghost.reveal v) = let u = coerce_steel (fun _ -> R.read_pt r) in return u let write (#a:Type0) (#v:erased a) (r:ref a) (x:a) : STT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = coerce_steel (fun _ -> R.write_pt r x); return () let free (#a:Type0) (#v:erased a) (r:ref a) : STT unit (pts_to r full_perm v) (fun _ -> emp) = coerce_steel(fun _ -> R.free_pt r); return () /// Local primitive, to be extracted to Low* EPushFrame. To remember /// that we need to call some pop_frame later, we insert some dummy /// vprop into the context. let _stack_frame : vprop = pure True let _push_frame () : STT unit emp (fun _ -> _stack_frame) = rewrite (pure True) _stack_frame
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Reference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> Steel.ST.Effect.ST (Steel.ST.Reference.ref a)
Steel.ST.Effect.ST
[]
[]
[ "Steel.ST.Reference.alloc", "Steel.ST.Reference.ref", "Steel.Effect.Common.emp", "Steel.ST.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.Effect.Common.vprop", "Prims.l_True", "Prims.b2t", "Prims.op_Negation", "Steel.ST.Reference.is_null" ]
[]
false
true
false
false
false
let _alloca (#a: Type) (x: a) : ST (ref a) emp (fun r -> pts_to r full_perm x) (requires True) (ensures fun r -> not (is_null r)) =
alloc x
false
Steel.ST.Array.fst
Steel.ST.Array.equal_up_to
val equal_up_to (#t: _) (s0 s1: Seq.seq t) (v: option US.t) : prop
val equal_up_to (#t: _) (s0 s1: Seq.seq t) (v: option US.t) : prop
let equal_up_to #t (s0: Seq.seq t) (s1: Seq.seq t) (v : option US.t) : prop = Seq.length s0 = Seq.length s1 /\ (match v with | None -> Ghost.reveal s0 =!= Ghost.reveal s1 | Some v -> US.v v <= Seq.length s0 /\ Seq.slice s0 0 (US.v v) `Seq.equal` Seq.slice s1 0 (US.v v))
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 104, "end_line": 249, "start_col": 0, "start_line": 242 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2 let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt) let length_fits a = H.length_fits a let pts_to a p s = H.pts_to a p (seq_map raise s) let pts_to_length a s = H.pts_to_length a _ let h_array_eq' (#t: Type u#1) (a1 a2: H.array t) : Lemma (requires ( dfst a1 == dfst a2 /\ (Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2) )) (ensures ( a1 == a2 )) = () let pts_to_not_null #_ #t #p a s = let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in assert (a =!= H.null #(raise_t t)); Classical.move_requires (h_array_eq' a) (H.null #(raise_t t)); noop () let pts_to_inj a p1 s1 p2 s2 = H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2) /// Non-selector operations. let malloc x n = let res = H.malloc (raise x) n in assert (seq_map raise (Seq.create (US.v n) x) `Seq.equal` Seq.create (US.v n) (raise x)); rewrite (H.pts_to res _ _) (pts_to res _ _); return res let free #_ x = let s = elim_exists () in rewrite (pts_to x _ _) (H.pts_to x P.full_perm (seq_map raise s)); H.free x let share #_ #_ #x a p p1 p2 = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); H.share a p p1 p2; rewrite (H.pts_to a p1 _) (pts_to a p1 x); rewrite (H.pts_to a p2 _) (pts_to a p2 x) let gather #_ #_ a #x1 p1 #x2 p2 = rewrite (pts_to a p1 _) (H.pts_to a p1 (seq_map raise x1)); rewrite (pts_to a p2 _) (H.pts_to a p2 (seq_map raise x2)); H.gather a p1 p2; rewrite (H.pts_to a _ _) (pts_to _ _ _) let index #_ #p a #s i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise s)); let res = H.index a i in rewrite (H.pts_to _ _ _) (pts_to _ _ _); return (lower res) let upd #_ a #s i v = rewrite (pts_to a _ _) (H.pts_to a P.full_perm (seq_map raise s)); H.upd a i (raise v); assert (seq_map raise (Seq.upd s (US.v i) v) `Seq.equal` Seq.upd (seq_map raise s) (US.v i) (raise v)); rewrite (H.pts_to _ _ _) (pts_to _ _ _) let ghost_join #_ #_ #x1 #x2 #p a1 a2 h = rewrite (pts_to a1 _ _) (H.pts_to a1 p (seq_map raise x1)); rewrite (pts_to a2 _ _) (H.pts_to a2 p (seq_map raise x2)); H.ghost_join a1 a2 h; assert (seq_map raise (x1 `Seq.append` x2) `Seq.equal` (seq_map raise x1 `Seq.append` seq_map raise x2)); rewrite (H.pts_to _ _ _) (H.pts_to (merge a1 a2) p (seq_map raise (x1 `Seq.append` x2))); rewrite (H.pts_to _ _ _) (pts_to (merge a1 a2) _ _) let ptr_shift p off = H.ptr_shift p off let ghost_split #_ #_ #x #p a i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); let _ = H.ghost_split a i in //H.ghost_split a i; assert (seq_map raise (Seq.slice x 0 (US.v i)) `Seq.equal` Seq.slice (seq_map raise x) 0 (US.v i)); rewrite (H.pts_to (H.split_l a i) _ _) (H.pts_to (split_l a i) p (seq_map raise (Seq.slice x 0 (US.v i)))); rewrite (H.pts_to (split_l a i) _ _) (pts_to (split_l a i) _ _); assert (seq_map raise (Seq.slice x (US.v i) (Seq.length x)) `Seq.equal` Seq.slice (seq_map raise x) (US.v i) (Seq.length (seq_map raise x))); Seq.lemma_split x (US.v i); rewrite (H.pts_to (H.split_r a i) _ _) (H.pts_to (split_r a i) p (seq_map raise (Seq.slice x (US.v i) (Seq.length x)))); rewrite (H.pts_to (split_r a i) _ _) (pts_to (split_r a i) _ _) let memcpy a0 a1 l = H.memcpy a0 a1 l //////////////////////////////////////////////////////////////////////////////// // compare //////////////////////////////////////////////////////////////////////////////// module R = Steel.ST.Reference
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.Reference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Seq.Base.seq t -> s1: FStar.Seq.Base.seq t -> v: FStar.Pervasives.Native.option FStar.SizeT.t -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "FStar.Pervasives.Native.option", "FStar.SizeT.t", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.Seq.Base.length", "Prims.l_not", "Prims.eq2", "FStar.Ghost.reveal", "FStar.Ghost.hide", "Prims.op_LessThanOrEqual", "FStar.SizeT.v", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.logical", "Prims.prop" ]
[]
false
false
false
true
true
let equal_up_to #t (s0: Seq.seq t) (s1: Seq.seq t) (v: option US.t) : prop =
Seq.length s0 = Seq.length s1 /\ (match v with | None -> Ghost.reveal s0 =!= Ghost.reveal s1 | Some v -> US.v v <= Seq.length s0 /\ (Seq.slice s0 0 (US.v v)) `Seq.equal` (Seq.slice s1 0 (US.v v)))
false
Steel.ST.Array.fst
Steel.ST.Array.ptr_shift
val ptr_shift (#elt: Type) (p: ptr elt) (off: US.t) : Pure (ptr elt) (requires (offset p + US.v off <= base_len (base p))) (ensures (fun p' -> base p' == base p /\ offset p' == offset p + US.v off ))
val ptr_shift (#elt: Type) (p: ptr elt) (off: US.t) : Pure (ptr elt) (requires (offset p + US.v off <= base_len (base p))) (ensures (fun p' -> base p' == base p /\ offset p' == offset p + US.v off ))
let ptr_shift p off = H.ptr_shift p off
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 39, "end_line": 204, "start_col": 0, "start_line": 204 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2 let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt) let length_fits a = H.length_fits a let pts_to a p s = H.pts_to a p (seq_map raise s) let pts_to_length a s = H.pts_to_length a _ let h_array_eq' (#t: Type u#1) (a1 a2: H.array t) : Lemma (requires ( dfst a1 == dfst a2 /\ (Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2) )) (ensures ( a1 == a2 )) = () let pts_to_not_null #_ #t #p a s = let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in assert (a =!= H.null #(raise_t t)); Classical.move_requires (h_array_eq' a) (H.null #(raise_t t)); noop () let pts_to_inj a p1 s1 p2 s2 = H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2) /// Non-selector operations. let malloc x n = let res = H.malloc (raise x) n in assert (seq_map raise (Seq.create (US.v n) x) `Seq.equal` Seq.create (US.v n) (raise x)); rewrite (H.pts_to res _ _) (pts_to res _ _); return res let free #_ x = let s = elim_exists () in rewrite (pts_to x _ _) (H.pts_to x P.full_perm (seq_map raise s)); H.free x let share #_ #_ #x a p p1 p2 = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); H.share a p p1 p2; rewrite (H.pts_to a p1 _) (pts_to a p1 x); rewrite (H.pts_to a p2 _) (pts_to a p2 x) let gather #_ #_ a #x1 p1 #x2 p2 = rewrite (pts_to a p1 _) (H.pts_to a p1 (seq_map raise x1)); rewrite (pts_to a p2 _) (H.pts_to a p2 (seq_map raise x2)); H.gather a p1 p2; rewrite (H.pts_to a _ _) (pts_to _ _ _) let index #_ #p a #s i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise s)); let res = H.index a i in rewrite (H.pts_to _ _ _) (pts_to _ _ _); return (lower res) let upd #_ a #s i v = rewrite (pts_to a _ _) (H.pts_to a P.full_perm (seq_map raise s)); H.upd a i (raise v); assert (seq_map raise (Seq.upd s (US.v i) v) `Seq.equal` Seq.upd (seq_map raise s) (US.v i) (raise v)); rewrite (H.pts_to _ _ _) (pts_to _ _ _) let ghost_join #_ #_ #x1 #x2 #p a1 a2 h = rewrite (pts_to a1 _ _) (H.pts_to a1 p (seq_map raise x1)); rewrite (pts_to a2 _ _) (H.pts_to a2 p (seq_map raise x2)); H.ghost_join a1 a2 h; assert (seq_map raise (x1 `Seq.append` x2) `Seq.equal` (seq_map raise x1 `Seq.append` seq_map raise x2)); rewrite (H.pts_to _ _ _) (H.pts_to (merge a1 a2) p (seq_map raise (x1 `Seq.append` x2))); rewrite (H.pts_to _ _ _) (pts_to (merge a1 a2) _ _)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Steel.ST.Array.ptr elt -> off: FStar.SizeT.t -> Prims.Pure (Steel.ST.Array.ptr elt)
Prims.Pure
[]
[]
[ "Steel.ST.Array.ptr", "FStar.SizeT.t", "Steel.ST.HigherArray.ptr_shift", "Steel.ST.Array.raise_t" ]
[]
false
false
false
false
false
let ptr_shift p off =
H.ptr_shift p off
false
Steel.ST.Array.fst
Steel.ST.Array.within_bounds
val within_bounds (x: option US.t) (l: US.t) (b: Ghost.erased bool) : prop
val within_bounds (x: option US.t) (l: US.t) (b: Ghost.erased bool) : prop
let within_bounds (x:option US.t) (l:US.t) (b:Ghost.erased bool) : prop = if b then Some? x /\ US.(Some?.v x <^ l) else None? x \/ US.(Some?.v x >=^ l)
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 38, "end_line": 253, "start_col": 0, "start_line": 251 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2 let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt) let length_fits a = H.length_fits a let pts_to a p s = H.pts_to a p (seq_map raise s) let pts_to_length a s = H.pts_to_length a _ let h_array_eq' (#t: Type u#1) (a1 a2: H.array t) : Lemma (requires ( dfst a1 == dfst a2 /\ (Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2) )) (ensures ( a1 == a2 )) = () let pts_to_not_null #_ #t #p a s = let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in assert (a =!= H.null #(raise_t t)); Classical.move_requires (h_array_eq' a) (H.null #(raise_t t)); noop () let pts_to_inj a p1 s1 p2 s2 = H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2) /// Non-selector operations. let malloc x n = let res = H.malloc (raise x) n in assert (seq_map raise (Seq.create (US.v n) x) `Seq.equal` Seq.create (US.v n) (raise x)); rewrite (H.pts_to res _ _) (pts_to res _ _); return res let free #_ x = let s = elim_exists () in rewrite (pts_to x _ _) (H.pts_to x P.full_perm (seq_map raise s)); H.free x let share #_ #_ #x a p p1 p2 = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); H.share a p p1 p2; rewrite (H.pts_to a p1 _) (pts_to a p1 x); rewrite (H.pts_to a p2 _) (pts_to a p2 x) let gather #_ #_ a #x1 p1 #x2 p2 = rewrite (pts_to a p1 _) (H.pts_to a p1 (seq_map raise x1)); rewrite (pts_to a p2 _) (H.pts_to a p2 (seq_map raise x2)); H.gather a p1 p2; rewrite (H.pts_to a _ _) (pts_to _ _ _) let index #_ #p a #s i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise s)); let res = H.index a i in rewrite (H.pts_to _ _ _) (pts_to _ _ _); return (lower res) let upd #_ a #s i v = rewrite (pts_to a _ _) (H.pts_to a P.full_perm (seq_map raise s)); H.upd a i (raise v); assert (seq_map raise (Seq.upd s (US.v i) v) `Seq.equal` Seq.upd (seq_map raise s) (US.v i) (raise v)); rewrite (H.pts_to _ _ _) (pts_to _ _ _) let ghost_join #_ #_ #x1 #x2 #p a1 a2 h = rewrite (pts_to a1 _ _) (H.pts_to a1 p (seq_map raise x1)); rewrite (pts_to a2 _ _) (H.pts_to a2 p (seq_map raise x2)); H.ghost_join a1 a2 h; assert (seq_map raise (x1 `Seq.append` x2) `Seq.equal` (seq_map raise x1 `Seq.append` seq_map raise x2)); rewrite (H.pts_to _ _ _) (H.pts_to (merge a1 a2) p (seq_map raise (x1 `Seq.append` x2))); rewrite (H.pts_to _ _ _) (pts_to (merge a1 a2) _ _) let ptr_shift p off = H.ptr_shift p off let ghost_split #_ #_ #x #p a i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); let _ = H.ghost_split a i in //H.ghost_split a i; assert (seq_map raise (Seq.slice x 0 (US.v i)) `Seq.equal` Seq.slice (seq_map raise x) 0 (US.v i)); rewrite (H.pts_to (H.split_l a i) _ _) (H.pts_to (split_l a i) p (seq_map raise (Seq.slice x 0 (US.v i)))); rewrite (H.pts_to (split_l a i) _ _) (pts_to (split_l a i) _ _); assert (seq_map raise (Seq.slice x (US.v i) (Seq.length x)) `Seq.equal` Seq.slice (seq_map raise x) (US.v i) (Seq.length (seq_map raise x))); Seq.lemma_split x (US.v i); rewrite (H.pts_to (H.split_r a i) _ _) (H.pts_to (split_r a i) p (seq_map raise (Seq.slice x (US.v i) (Seq.length x)))); rewrite (H.pts_to (split_r a i) _ _) (pts_to (split_r a i) _ _) let memcpy a0 a1 l = H.memcpy a0 a1 l //////////////////////////////////////////////////////////////////////////////// // compare //////////////////////////////////////////////////////////////////////////////// module R = Steel.ST.Reference #push-options "--fuel 0 --ifuel 1 --z3rlimit_factor 2" let equal_up_to #t (s0: Seq.seq t) (s1: Seq.seq t) (v : option US.t) : prop = Seq.length s0 = Seq.length s1 /\ (match v with | None -> Ghost.reveal s0 =!= Ghost.reveal s1 | Some v -> US.v v <= Seq.length s0 /\ Seq.slice s0 0 (US.v v) `Seq.equal` Seq.slice s1 0 (US.v v))
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.Reference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Pervasives.Native.option FStar.SizeT.t -> l: FStar.SizeT.t -> b: FStar.Ghost.erased Prims.bool -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.option", "FStar.SizeT.t", "FStar.Ghost.erased", "Prims.bool", "FStar.Ghost.reveal", "Prims.l_and", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.SizeT.op_Less_Hat", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.l_or", "FStar.Pervasives.Native.uu___is_None", "FStar.SizeT.op_Greater_Equals_Hat", "Prims.prop" ]
[]
false
false
false
true
true
let within_bounds (x: option US.t) (l: US.t) (b: Ghost.erased bool) : prop =
if b then Some? x /\ US.(Some?.v x <^ l) else None? x \/ US.(Some?.v x >=^ l)
false
Steel.ST.Array.fst
Steel.ST.Array.intro_fits_u32
val intro_fits_u32 (_:unit) : STT (squash (US.fits_u32)) emp (fun _ -> emp)
val intro_fits_u32 (_:unit) : STT (squash (US.fits_u32)) emp (fun _ -> emp)
let intro_fits_u32 () = H.intro_fits_u32 ()
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 537, "start_col": 0, "start_line": 537 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2 let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt) let length_fits a = H.length_fits a let pts_to a p s = H.pts_to a p (seq_map raise s) let pts_to_length a s = H.pts_to_length a _ let h_array_eq' (#t: Type u#1) (a1 a2: H.array t) : Lemma (requires ( dfst a1 == dfst a2 /\ (Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2) )) (ensures ( a1 == a2 )) = () let pts_to_not_null #_ #t #p a s = let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in assert (a =!= H.null #(raise_t t)); Classical.move_requires (h_array_eq' a) (H.null #(raise_t t)); noop () let pts_to_inj a p1 s1 p2 s2 = H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2) /// Non-selector operations. let malloc x n = let res = H.malloc (raise x) n in assert (seq_map raise (Seq.create (US.v n) x) `Seq.equal` Seq.create (US.v n) (raise x)); rewrite (H.pts_to res _ _) (pts_to res _ _); return res let free #_ x = let s = elim_exists () in rewrite (pts_to x _ _) (H.pts_to x P.full_perm (seq_map raise s)); H.free x let share #_ #_ #x a p p1 p2 = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); H.share a p p1 p2; rewrite (H.pts_to a p1 _) (pts_to a p1 x); rewrite (H.pts_to a p2 _) (pts_to a p2 x) let gather #_ #_ a #x1 p1 #x2 p2 = rewrite (pts_to a p1 _) (H.pts_to a p1 (seq_map raise x1)); rewrite (pts_to a p2 _) (H.pts_to a p2 (seq_map raise x2)); H.gather a p1 p2; rewrite (H.pts_to a _ _) (pts_to _ _ _) let index #_ #p a #s i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise s)); let res = H.index a i in rewrite (H.pts_to _ _ _) (pts_to _ _ _); return (lower res) let upd #_ a #s i v = rewrite (pts_to a _ _) (H.pts_to a P.full_perm (seq_map raise s)); H.upd a i (raise v); assert (seq_map raise (Seq.upd s (US.v i) v) `Seq.equal` Seq.upd (seq_map raise s) (US.v i) (raise v)); rewrite (H.pts_to _ _ _) (pts_to _ _ _) let ghost_join #_ #_ #x1 #x2 #p a1 a2 h = rewrite (pts_to a1 _ _) (H.pts_to a1 p (seq_map raise x1)); rewrite (pts_to a2 _ _) (H.pts_to a2 p (seq_map raise x2)); H.ghost_join a1 a2 h; assert (seq_map raise (x1 `Seq.append` x2) `Seq.equal` (seq_map raise x1 `Seq.append` seq_map raise x2)); rewrite (H.pts_to _ _ _) (H.pts_to (merge a1 a2) p (seq_map raise (x1 `Seq.append` x2))); rewrite (H.pts_to _ _ _) (pts_to (merge a1 a2) _ _) let ptr_shift p off = H.ptr_shift p off let ghost_split #_ #_ #x #p a i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); let _ = H.ghost_split a i in //H.ghost_split a i; assert (seq_map raise (Seq.slice x 0 (US.v i)) `Seq.equal` Seq.slice (seq_map raise x) 0 (US.v i)); rewrite (H.pts_to (H.split_l a i) _ _) (H.pts_to (split_l a i) p (seq_map raise (Seq.slice x 0 (US.v i)))); rewrite (H.pts_to (split_l a i) _ _) (pts_to (split_l a i) _ _); assert (seq_map raise (Seq.slice x (US.v i) (Seq.length x)) `Seq.equal` Seq.slice (seq_map raise x) (US.v i) (Seq.length (seq_map raise x))); Seq.lemma_split x (US.v i); rewrite (H.pts_to (H.split_r a i) _ _) (H.pts_to (split_r a i) p (seq_map raise (Seq.slice x (US.v i) (Seq.length x)))); rewrite (H.pts_to (split_r a i) _ _) (pts_to (split_r a i) _ _) let memcpy a0 a1 l = H.memcpy a0 a1 l //////////////////////////////////////////////////////////////////////////////// // compare //////////////////////////////////////////////////////////////////////////////// module R = Steel.ST.Reference #push-options "--fuel 0 --ifuel 1 --z3rlimit_factor 2" let equal_up_to #t (s0: Seq.seq t) (s1: Seq.seq t) (v : option US.t) : prop = Seq.length s0 = Seq.length s1 /\ (match v with | None -> Ghost.reveal s0 =!= Ghost.reveal s1 | Some v -> US.v v <= Seq.length s0 /\ Seq.slice s0 0 (US.v v) `Seq.equal` Seq.slice s1 0 (US.v v)) let within_bounds (x:option US.t) (l:US.t) (b:Ghost.erased bool) : prop = if b then Some? x /\ US.(Some?.v x <^ l) else None? x \/ US.(Some?.v x >=^ l) let compare_inv (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (s0: Seq.seq t) (s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (b: bool) = pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (x:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l b)) let elim_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (b: bool) : STGhostT (Ghost.erased (option US.t)) o (compare_inv a0 a1 s0 s1 l ctr b) (fun x -> let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l b)) = let open US in assert_spinoff ((compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr b) == (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l b)))); rewrite (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr b) (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l b))); let _v = elim_exists () in _v let intro_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (x: Ghost.erased (option US.t)) (b:bool { within_bounds x l b }) : STGhostT unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x)) (fun _ -> compare_inv a0 a1 s0 s1 l ctr (Ghost.hide b)) = let open US in intro_pure (within_bounds x l (Ghost.hide b)); intro_exists_erased x (fun (x:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l (Ghost.hide b))); assert_norm ((compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) == (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l (Ghost.hide b))))); rewrite (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l (Ghost.hide b)))) (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) let intro_exists_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (x: Ghost.erased (option US.t)) : STGhostT unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) = let b : bool = match Ghost.reveal x with | None -> false | Some x -> US.(x <^ l) in assert (within_bounds x l b); intro_compare_inv #_ #_ #p0 #p1 a0 a1 #s0 #s1 l ctr x b; intro_exists _ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr) let extend_equal_up_to_lemma (#t:Type0) (s0:Seq.seq t) (s1:Seq.seq t) (i:nat{ i < Seq.length s0 /\ Seq.length s0 == Seq.length s1 }) : Lemma (requires Seq.equal (Seq.slice s0 0 i) (Seq.slice s1 0 i) /\ Seq.index s0 i == Seq.index s1 i) (ensures Seq.equal (Seq.slice s0 0 (i + 1)) (Seq.slice s1 0 (i + 1))) = assert (forall k. k < i ==> Seq.index s0 k == Seq.index (Seq.slice s0 0 i) k /\ Seq.index s1 k == Seq.index (Seq.slice s1 0 i) k) let extend_equal_up_to (#o:_) (#t:Type0) (#s0:Seq.seq t) (#s1:Seq.seq t) (len:US.t) (i:US.t{ Seq.length s0 == Seq.length s1 /\ US.(i <^ len) /\ US.v len == Seq.length s0 } ) : STGhost unit o (pure (equal_up_to s0 s1 (Some i))) (fun _ -> pure (equal_up_to s0 s1 (Some US.(i +^ 1sz)))) (requires Seq.index s0 (US.v i) == Seq.index s1 (US.v i)) (ensures fun _ -> True) = elim_pure _; extend_equal_up_to_lemma s0 s1 (US.v i); intro_pure (equal_up_to s0 s1 (Some US.(i +^ 1sz))) let extend_equal_up_to_neg (#o:_) (#t:Type0) (#s0:Seq.seq t) (#s1:Seq.seq t) (len:US.t) (i:US.t{ Seq.length s0 == Seq.length s1 /\ US.(i <^ len) /\ US.v len == Seq.length s0 } ) : STGhost unit o (pure (equal_up_to s0 s1 (Some i))) (fun _ -> pure (equal_up_to s0 s1 None)) (requires Seq.index s0 (US.v i) =!= Seq.index s1 (US.v i)) (ensures fun _ -> True) = elim_pure _; intro_pure _ let init_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) : STGhost unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm (Some 0sz)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) (requires ( length a0 > 0 /\ length a0 == length a1 /\ US.v l == length a0 )) (ensures (fun _ -> True)) = pts_to_length a0 _; pts_to_length a1 _; intro_pure (equal_up_to s0 s1 (Ghost.hide (Some 0sz))); rewrite (R.pts_to ctr Steel.FractionalPermission.full_perm (Some 0sz)) (R.pts_to ctr Steel.FractionalPermission.full_perm (Ghost.hide (Some 0sz))); intro_exists_compare_inv a0 a1 l ctr (Ghost.hide (Some 0sz)) let compare_pts (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Ghost.erased (Seq.seq t)) (#s1: Ghost.erased (Seq.seq t)) (l:US.t) : ST bool (pts_to a0 p0 s0 `star` pts_to a1 p1 s1) (fun _ -> pts_to a0 p0 s0 `star` pts_to a1 p1 s1) (requires length a0 > 0 /\ length a0 == length a1 /\ US.v l == length a0 ) (ensures fun b -> b = (Ghost.reveal s0 = Ghost.reveal s1)) = pts_to_length a0 _; pts_to_length a1 _; let ctr = R.alloc (Some 0sz) in let cond () : STT bool (exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) (fun b -> compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) = let _b = elim_exists () in let _ = elim_compare_inv _ _ _ _ _ in let x = R.read ctr in elim_pure (within_bounds _ _ _); match x with | None -> intro_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr _ false; return false | Some x -> let res = US.(x <^ l) in intro_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr _ res; return res in let body () : STT unit (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide true)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) = let _i = elim_compare_inv _ _ _ _ _ in elim_pure (within_bounds _ _ _); let Some i = R.read ctr in assert_spinoff ((pure (equal_up_to s0 s1 _i)) == (pure (equal_up_to s0 s1 (Some i)))); rewrite (pure (equal_up_to s0 s1 _i)) (pure (equal_up_to s0 s1 (Some i))); let v0 = index a0 i in let v1 = index a1 i in if v0 = v1 then ( R.write ctr (Some US.(i +^ 1sz)); extend_equal_up_to l i; intro_exists_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr (Ghost.hide (Some (US.(i +^ 1sz)))) ) else ( R.write ctr None; extend_equal_up_to_neg l i; intro_exists_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr (Ghost.hide None) ) in init_compare_inv a0 a1 l ctr; Steel.ST.Loops.while_loop (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr) cond body; let _ = elim_compare_inv _ _ _ _ _ in elim_pure (equal_up_to _ _ _); let v = R.read ctr in R.free ctr; elim_pure (within_bounds _ _ _); match v with | None -> return false | Some _ -> return true let compare #t #p0 #p1 a0 a1 #s0 #s1 l = pts_to_length a0 _; pts_to_length a1 _; if l = 0sz then ( assert (Seq.equal s0 s1); return true ) else ( compare_pts a0 a1 l ) #pop-options
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.Reference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Steel.ST.Effect.STT (Prims.squash FStar.SizeT.fits_u32)
Steel.ST.Effect.STT
[]
[]
[ "Prims.unit", "Steel.ST.HigherArray.intro_fits_u32", "Prims.squash", "FStar.SizeT.fits_u32" ]
[]
false
true
true
false
false
let intro_fits_u32 () =
H.intro_fits_u32 ()
false
Steel.ST.Array.fst
Steel.ST.Array.intro_fits_u64
val intro_fits_u64 (_:unit) : STT (squash (US.fits_u64)) emp (fun _ -> emp)
val intro_fits_u64 (_:unit) : STT (squash (US.fits_u64)) emp (fun _ -> emp)
let intro_fits_u64 () = H.intro_fits_u64 ()
{ "file_name": "lib/steel/Steel.ST.Array.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 538, "start_col": 0, "start_line": 538 }
(* Copyright 2020, 2021, 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array module US = FStar.SizeT /// Lifting a value of universe 0 to universe 1. We use /// FStar.Universe, since FStar.Extraction.Krml is set to extract /// those functions to identity. inline_for_extraction [@@ noextract_to "krml"] let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t inline_for_extraction [@@noextract_to "krml"] let raise (#t: Type) (x: t) : Tot (raise_t t) = FStar.Universe.raise_val x inline_for_extraction [@@noextract_to "krml"] let lower (#t: Type) (x: raise_t t) : Tot t = FStar.Universe.downgrade_val x /// A map operation on sequences. Here we only need Ghost versions, /// because such sequences are only used in vprops or with their /// selectors. let rec seq_map (#t: Type u#a) (#t' : Type u#b) (f: (t -> GTot t')) (s: Seq.seq t) : Ghost (Seq.seq t') (requires True) (ensures (fun s' -> Seq.length s' == Seq.length s /\ (forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i)) )) (decreases (Seq.length s)) = if Seq.length s = 0 then Seq.empty else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s))) let seq_map_append (#t: Type u#a) (#t': Type u#b) (f: (t -> GTot t')) (s1 s2: Seq.seq t) : Lemma (seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2)) = () let seq_map_raise_inj (#elt: Type0) (s1 s2: Seq.seq elt) : Lemma (requires (seq_map raise s1 == seq_map raise s2)) (ensures (s1 == s2)) [SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)] = assert (seq_map lower (seq_map raise s1) `Seq.equal` s1); assert (seq_map lower (seq_map raise s2) `Seq.equal` s2) /// Implementation of the interface /// base, ptr, array, pts_to module H = Steel.ST.HigherArray let base_t elt = H.base_t (raise_t elt) let base_len b = H.base_len b let ptr elt = H.ptr (raise_t elt) let null_ptr elt = H.null_ptr (raise_t elt) let is_null_ptr p = H.is_null_ptr p let base p = H.base p let offset p = H.offset p let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2 let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt) let length_fits a = H.length_fits a let pts_to a p s = H.pts_to a p (seq_map raise s) let pts_to_length a s = H.pts_to_length a _ let h_array_eq' (#t: Type u#1) (a1 a2: H.array t) : Lemma (requires ( dfst a1 == dfst a2 /\ (Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2) )) (ensures ( a1 == a2 )) = () let pts_to_not_null #_ #t #p a s = let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in assert (a =!= H.null #(raise_t t)); Classical.move_requires (h_array_eq' a) (H.null #(raise_t t)); noop () let pts_to_inj a p1 s1 p2 s2 = H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2) /// Non-selector operations. let malloc x n = let res = H.malloc (raise x) n in assert (seq_map raise (Seq.create (US.v n) x) `Seq.equal` Seq.create (US.v n) (raise x)); rewrite (H.pts_to res _ _) (pts_to res _ _); return res let free #_ x = let s = elim_exists () in rewrite (pts_to x _ _) (H.pts_to x P.full_perm (seq_map raise s)); H.free x let share #_ #_ #x a p p1 p2 = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); H.share a p p1 p2; rewrite (H.pts_to a p1 _) (pts_to a p1 x); rewrite (H.pts_to a p2 _) (pts_to a p2 x) let gather #_ #_ a #x1 p1 #x2 p2 = rewrite (pts_to a p1 _) (H.pts_to a p1 (seq_map raise x1)); rewrite (pts_to a p2 _) (H.pts_to a p2 (seq_map raise x2)); H.gather a p1 p2; rewrite (H.pts_to a _ _) (pts_to _ _ _) let index #_ #p a #s i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise s)); let res = H.index a i in rewrite (H.pts_to _ _ _) (pts_to _ _ _); return (lower res) let upd #_ a #s i v = rewrite (pts_to a _ _) (H.pts_to a P.full_perm (seq_map raise s)); H.upd a i (raise v); assert (seq_map raise (Seq.upd s (US.v i) v) `Seq.equal` Seq.upd (seq_map raise s) (US.v i) (raise v)); rewrite (H.pts_to _ _ _) (pts_to _ _ _) let ghost_join #_ #_ #x1 #x2 #p a1 a2 h = rewrite (pts_to a1 _ _) (H.pts_to a1 p (seq_map raise x1)); rewrite (pts_to a2 _ _) (H.pts_to a2 p (seq_map raise x2)); H.ghost_join a1 a2 h; assert (seq_map raise (x1 `Seq.append` x2) `Seq.equal` (seq_map raise x1 `Seq.append` seq_map raise x2)); rewrite (H.pts_to _ _ _) (H.pts_to (merge a1 a2) p (seq_map raise (x1 `Seq.append` x2))); rewrite (H.pts_to _ _ _) (pts_to (merge a1 a2) _ _) let ptr_shift p off = H.ptr_shift p off let ghost_split #_ #_ #x #p a i = rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x)); let _ = H.ghost_split a i in //H.ghost_split a i; assert (seq_map raise (Seq.slice x 0 (US.v i)) `Seq.equal` Seq.slice (seq_map raise x) 0 (US.v i)); rewrite (H.pts_to (H.split_l a i) _ _) (H.pts_to (split_l a i) p (seq_map raise (Seq.slice x 0 (US.v i)))); rewrite (H.pts_to (split_l a i) _ _) (pts_to (split_l a i) _ _); assert (seq_map raise (Seq.slice x (US.v i) (Seq.length x)) `Seq.equal` Seq.slice (seq_map raise x) (US.v i) (Seq.length (seq_map raise x))); Seq.lemma_split x (US.v i); rewrite (H.pts_to (H.split_r a i) _ _) (H.pts_to (split_r a i) p (seq_map raise (Seq.slice x (US.v i) (Seq.length x)))); rewrite (H.pts_to (split_r a i) _ _) (pts_to (split_r a i) _ _) let memcpy a0 a1 l = H.memcpy a0 a1 l //////////////////////////////////////////////////////////////////////////////// // compare //////////////////////////////////////////////////////////////////////////////// module R = Steel.ST.Reference #push-options "--fuel 0 --ifuel 1 --z3rlimit_factor 2" let equal_up_to #t (s0: Seq.seq t) (s1: Seq.seq t) (v : option US.t) : prop = Seq.length s0 = Seq.length s1 /\ (match v with | None -> Ghost.reveal s0 =!= Ghost.reveal s1 | Some v -> US.v v <= Seq.length s0 /\ Seq.slice s0 0 (US.v v) `Seq.equal` Seq.slice s1 0 (US.v v)) let within_bounds (x:option US.t) (l:US.t) (b:Ghost.erased bool) : prop = if b then Some? x /\ US.(Some?.v x <^ l) else None? x \/ US.(Some?.v x >=^ l) let compare_inv (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (s0: Seq.seq t) (s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (b: bool) = pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (x:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l b)) let elim_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (b: bool) : STGhostT (Ghost.erased (option US.t)) o (compare_inv a0 a1 s0 s1 l ctr b) (fun x -> let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l b)) = let open US in assert_spinoff ((compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr b) == (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l b)))); rewrite (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr b) (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l b))); let _v = elim_exists () in _v let intro_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (x: Ghost.erased (option US.t)) (b:bool { within_bounds x l b }) : STGhostT unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x)) (fun _ -> compare_inv a0 a1 s0 s1 l ctr (Ghost.hide b)) = let open US in intro_pure (within_bounds x l (Ghost.hide b)); intro_exists_erased x (fun (x:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x) `star` pure (within_bounds x l (Ghost.hide b))); assert_norm ((compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) == (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l (Ghost.hide b))))); rewrite (pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` exists_ (fun (v:option US.t) -> R.pts_to ctr Steel.FractionalPermission.full_perm v `star` pure (equal_up_to s0 s1 v) `star` pure (within_bounds v l (Ghost.hide b)))) (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) let intro_exists_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) (x: Ghost.erased (option US.t)) : STGhostT unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm x `star` pure (equal_up_to s0 s1 x)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) = let b : bool = match Ghost.reveal x with | None -> false | Some x -> US.(x <^ l) in assert (within_bounds x l b); intro_compare_inv #_ #_ #p0 #p1 a0 a1 #s0 #s1 l ctr x b; intro_exists _ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr) let extend_equal_up_to_lemma (#t:Type0) (s0:Seq.seq t) (s1:Seq.seq t) (i:nat{ i < Seq.length s0 /\ Seq.length s0 == Seq.length s1 }) : Lemma (requires Seq.equal (Seq.slice s0 0 i) (Seq.slice s1 0 i) /\ Seq.index s0 i == Seq.index s1 i) (ensures Seq.equal (Seq.slice s0 0 (i + 1)) (Seq.slice s1 0 (i + 1))) = assert (forall k. k < i ==> Seq.index s0 k == Seq.index (Seq.slice s0 0 i) k /\ Seq.index s1 k == Seq.index (Seq.slice s1 0 i) k) let extend_equal_up_to (#o:_) (#t:Type0) (#s0:Seq.seq t) (#s1:Seq.seq t) (len:US.t) (i:US.t{ Seq.length s0 == Seq.length s1 /\ US.(i <^ len) /\ US.v len == Seq.length s0 } ) : STGhost unit o (pure (equal_up_to s0 s1 (Some i))) (fun _ -> pure (equal_up_to s0 s1 (Some US.(i +^ 1sz)))) (requires Seq.index s0 (US.v i) == Seq.index s1 (US.v i)) (ensures fun _ -> True) = elim_pure _; extend_equal_up_to_lemma s0 s1 (US.v i); intro_pure (equal_up_to s0 s1 (Some US.(i +^ 1sz))) let extend_equal_up_to_neg (#o:_) (#t:Type0) (#s0:Seq.seq t) (#s1:Seq.seq t) (len:US.t) (i:US.t{ Seq.length s0 == Seq.length s1 /\ US.(i <^ len) /\ US.v len == Seq.length s0 } ) : STGhost unit o (pure (equal_up_to s0 s1 (Some i))) (fun _ -> pure (equal_up_to s0 s1 None)) (requires Seq.index s0 (US.v i) =!= Seq.index s1 (US.v i)) (ensures fun _ -> True) = elim_pure _; intro_pure _ let init_compare_inv #o (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Seq.seq t) (#s1: Seq.seq t) (l:US.t) (ctr : R.ref (option US.t)) : STGhost unit o (let open US in pts_to a0 p0 s0 `star` pts_to a1 p1 s1 `star` R.pts_to ctr Steel.FractionalPermission.full_perm (Some 0sz)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) (requires ( length a0 > 0 /\ length a0 == length a1 /\ US.v l == length a0 )) (ensures (fun _ -> True)) = pts_to_length a0 _; pts_to_length a1 _; intro_pure (equal_up_to s0 s1 (Ghost.hide (Some 0sz))); rewrite (R.pts_to ctr Steel.FractionalPermission.full_perm (Some 0sz)) (R.pts_to ctr Steel.FractionalPermission.full_perm (Ghost.hide (Some 0sz))); intro_exists_compare_inv a0 a1 l ctr (Ghost.hide (Some 0sz)) let compare_pts (#t:eqtype) (#p0 #p1:perm) (a0 a1:array t) (#s0: Ghost.erased (Seq.seq t)) (#s1: Ghost.erased (Seq.seq t)) (l:US.t) : ST bool (pts_to a0 p0 s0 `star` pts_to a1 p1 s1) (fun _ -> pts_to a0 p0 s0 `star` pts_to a1 p1 s1) (requires length a0 > 0 /\ length a0 == length a1 /\ US.v l == length a0 ) (ensures fun b -> b = (Ghost.reveal s0 = Ghost.reveal s1)) = pts_to_length a0 _; pts_to_length a1 _; let ctr = R.alloc (Some 0sz) in let cond () : STT bool (exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) (fun b -> compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) = let _b = elim_exists () in let _ = elim_compare_inv _ _ _ _ _ in let x = R.read ctr in elim_pure (within_bounds _ _ _); match x with | None -> intro_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr _ false; return false | Some x -> let res = US.(x <^ l) in intro_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr _ res; return res in let body () : STT unit (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide true)) (fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)) = let _i = elim_compare_inv _ _ _ _ _ in elim_pure (within_bounds _ _ _); let Some i = R.read ctr in assert_spinoff ((pure (equal_up_to s0 s1 _i)) == (pure (equal_up_to s0 s1 (Some i)))); rewrite (pure (equal_up_to s0 s1 _i)) (pure (equal_up_to s0 s1 (Some i))); let v0 = index a0 i in let v1 = index a1 i in if v0 = v1 then ( R.write ctr (Some US.(i +^ 1sz)); extend_equal_up_to l i; intro_exists_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr (Ghost.hide (Some (US.(i +^ 1sz)))) ) else ( R.write ctr None; extend_equal_up_to_neg l i; intro_exists_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr (Ghost.hide None) ) in init_compare_inv a0 a1 l ctr; Steel.ST.Loops.while_loop (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr) cond body; let _ = elim_compare_inv _ _ _ _ _ in elim_pure (equal_up_to _ _ _); let v = R.read ctr in R.free ctr; elim_pure (within_bounds _ _ _); match v with | None -> return false | Some _ -> return true let compare #t #p0 #p1 a0 a1 #s0 #s1 l = pts_to_length a0 _; pts_to_length a1 _; if l = 0sz then ( assert (Seq.equal s0 s1); return true ) else ( compare_pts a0 a1 l ) #pop-options
{ "checked_file": "/", "dependencies": [ "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.HigherArray.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.fst" }
[ { "abbrev": true, "full_module": "Steel.ST.Reference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.ST.HigherArray", "short_module": "H" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Steel.ST.Effect.STT (Prims.squash FStar.SizeT.fits_u64)
Steel.ST.Effect.STT
[]
[]
[ "Prims.unit", "Steel.ST.HigherArray.intro_fits_u64", "Prims.squash", "FStar.SizeT.fits_u64" ]
[]
false
true
true
false
false
let intro_fits_u64 () =
H.intro_fits_u64 ()
false