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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.testify_forall | val testify_forall (#c:Type) (#p:(c -> mem -> Type0))
($s:squash (forall (x:c). witnessed (p x)))
:ST unit (requires (fun h -> True))
(ensures (fun h0 _ h1 -> h0==h1 /\ (forall (x:c). p x h1))) | val testify_forall (#c:Type) (#p:(c -> mem -> Type0))
($s:squash (forall (x:c). witnessed (p x)))
:ST unit (requires (fun h -> True))
(ensures (fun h0 _ h1 -> h0==h1 /\ (forall (x:c). p x h1))) | let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h) | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 271,
"start_col": 0,
"start_line": 269
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | $s: Prims.squash (forall (x: c). FStar.HyperStack.ST.witnessed (p x))
-> FStar.HyperStack.ST.ST Prims.unit | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.squash",
"Prims.l_Forall",
"FStar.HyperStack.ST.witnessed",
"FStar.HyperStack.ST.gst_recall",
"Prims.unit",
"FStar.Monotonic.Witnessed.lemma_witnessed_forall",
"FStar.HyperStack.ST.mem_rel"
] | [] | false | true | false | false | false | let testify_forall #c #p $s =
| W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x: c). p x h) | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.testify_forall_region_contains_pred | val testify_forall_region_contains_pred (#c:Type) (#p:(c -> GTot rid))
($s:squash (forall (x:c). witnessed (region_contains_pred (p x))))
:ST unit (requires (fun _ -> True))
(ensures (fun h0 _ h1 -> h0 == h1 /\
(forall (x:c). HS.is_eternal_region_hs (p x) ==> h1 `contains_region` (p x)))) | val testify_forall_region_contains_pred (#c:Type) (#p:(c -> GTot rid))
($s:squash (forall (x:c). witnessed (region_contains_pred (p x))))
:ST unit (requires (fun _ -> True))
(ensures (fun h0 _ h1 -> h0 == h1 /\
(forall (x:c). HS.is_eternal_region_hs (p x) ==> h1 `contains_region` (p x)))) | let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 18,
"end_line": 276,
"start_col": 0,
"start_line": 273
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
$s:
Prims.squash (forall (x: c).
FStar.HyperStack.ST.witnessed (FStar.HyperStack.ST.region_contains_pred (p x)))
-> FStar.HyperStack.ST.ST Prims.unit | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"Prims.squash",
"Prims.l_Forall",
"FStar.HyperStack.ST.witnessed",
"FStar.HyperStack.ST.region_contains_pred",
"FStar.HyperStack.ST.testify_forall",
"Prims.unit",
"FStar.HyperStack.ST.mem_predicate"
] | [] | false | true | false | false | false | let testify_forall_region_contains_pred #c #p $s =
| let p' (x: c) : mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x: c). witnessed (p' x)) = () in
testify_forall s | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.recall | val recall (#a:Type) (#rel:preorder a) (r:mreference a rel{not (HS.is_mm r)})
:Stack unit (requires (fun m -> is_eternal_region (HS.frameOf r) \/ m `contains_region` (HS.frameOf r)))
(ensures (fun m0 _ m1 -> m0 == m1 /\ m1 `contains` r)) | val recall (#a:Type) (#rel:preorder a) (r:mreference a rel{not (HS.is_mm r)})
:Stack unit (requires (fun m -> is_eternal_region (HS.frameOf r) \/ m `contains_region` (HS.frameOf r)))
(ensures (fun m0 _ m1 -> m0 == m1 /\ m1 `contains` r)) | let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r)) | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 241,
"start_col": 0,
"start_line": 239
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.HyperStack.ST.mreference a rel {Prims.op_Negation (FStar.Monotonic.HyperStack.is_mm r)}
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Preorder.preorder",
"FStar.HyperStack.ST.mreference",
"Prims.b2t",
"Prims.op_Negation",
"FStar.Monotonic.HyperStack.is_mm",
"FStar.HyperStack.ST.gst_recall",
"FStar.HyperStack.ST.region_contains_pred",
"FStar.Monotonic.HyperStack.frameOf",
"Prims.unit",
"FStar.HyperStack.ST.ref_contains_pred"
] | [] | false | true | false | false | false | let recall #_ #_ r =
| gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r)) | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.recall_p | val recall_p (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:ST unit (fun h0 -> ((is_eternal_region (HS.frameOf r) /\ not (HS.is_mm r)) \/ h0 `HS.contains` r) /\ token_p r p)
(fun h0 _ h1 -> h0 == h1 /\ h0 `HS.contains` r /\ p h0) | val recall_p (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:ST unit (fun h0 -> ((is_eternal_region (HS.frameOf r) /\ not (HS.is_mm r)) \/ h0 `HS.contains` r) /\ token_p r p)
(fun h0 _ h1 -> h0 == h1 /\ h0 `HS.contains` r /\ p h0) | let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p) | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 298,
"start_col": 0,
"start_line": 295
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.HyperStack.ST.mreference a rel -> p: FStar.HyperStack.ST.mem_predicate
-> FStar.HyperStack.ST.ST Prims.unit | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Preorder.preorder",
"FStar.HyperStack.ST.mreference",
"FStar.HyperStack.ST.mem_predicate",
"FStar.HyperStack.ST.gst_recall",
"FStar.HyperStack.ST.mem_rel_predicate",
"Prims.unit",
"FStar.HyperStack.ST.region_contains_pred",
"FStar.Monotonic.HyperStack.frameOf",
"FStar.HyperStack.ST.ref_contains_pred"
] | [] | false | true | false | false | false | let recall_p #_ #_ r p =
| gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p) | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.get | val get (_:unit)
:Stack mem (requires (fun m -> True))
(ensures (fun m0 x m1 -> m0 == x /\ m1 == m0)) | val get (_:unit)
:Stack mem (requires (fun m -> True))
(ensures (fun m0 x m1 -> m0 == x /\ m1 == m0)) | let get _ = gst_get () | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 237,
"start_col": 0,
"start_line": 237
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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.HyperStack.ST.Stack FStar.Monotonic.HyperStack.mem | FStar.HyperStack.ST.Stack | [] | [] | [
"Prims.unit",
"FStar.HyperStack.ST.gst_get",
"FStar.Monotonic.HyperStack.mem"
] | [] | false | true | false | false | false | let get _ =
| gst_get () | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.witness_p | val witness_p (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:ST unit (fun h0 -> p h0 /\ p `stable_on` r)
(fun h0 _ h1 -> h0 == h1 /\ token_p r p) | val witness_p (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:ST unit (fun h0 -> p h0 /\ p `stable_on` r)
(fun h0 _ h1 -> h0 == h1 /\ token_p r p) | let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p) | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 293,
"start_col": 0,
"start_line": 289
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.HyperStack.ST.mreference a rel -> p: FStar.HyperStack.ST.mem_predicate
-> FStar.HyperStack.ST.ST Prims.unit | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Preorder.preorder",
"FStar.HyperStack.ST.mreference",
"FStar.HyperStack.ST.mem_predicate",
"FStar.HyperStack.ST.gst_witness",
"FStar.HyperStack.ST.mem_rel_predicate",
"Prims.unit",
"FStar.Monotonic.HyperStack.lemma_next_addr_contained_refs_addr",
"FStar.HyperStack.ST.gst_recall",
"FStar.HyperStack.ST.region_contains_pred",
"FStar.Monotonic.HyperStack.frameOf",
"FStar.HyperStack.ST.ref_contains_pred"
] | [] | false | true | false | false | false | let witness_p #_ #_ r p =
| gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p) | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.token_functoriality | val token_functoriality
(#a:Type0) (#rel:preorder a) (r:mreference a rel)
(p:mem_predicate{token_p r p}) (q:mem_predicate{forall (h:mem). p h ==> q h})
: Lemma (token_p r q) | val token_functoriality
(#a:Type0) (#rel:preorder a) (r:mreference a rel)
(p:mem_predicate{token_p r p}) (q:mem_predicate{forall (h:mem). p h ==> q h})
: Lemma (token_p r q) | let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q) | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 69,
"end_line": 301,
"start_col": 0,
"start_line": 300
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r: FStar.HyperStack.ST.mreference a rel ->
p: FStar.HyperStack.ST.mem_predicate{FStar.HyperStack.ST.token_p r p} ->
q: FStar.HyperStack.ST.mem_predicate{forall (h: FStar.Monotonic.HyperStack.mem). p h ==> q h}
-> FStar.Pervasives.Lemma (ensures FStar.HyperStack.ST.token_p r q) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Preorder.preorder",
"FStar.HyperStack.ST.mreference",
"FStar.HyperStack.ST.mem_predicate",
"FStar.HyperStack.ST.token_p",
"Prims.l_Forall",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_imp",
"FStar.HyperStack.ST.lemma_functoriality",
"FStar.HyperStack.ST.mem_rel_predicate",
"Prims.unit"
] | [] | true | false | true | false | false | let token_functoriality #_ #_ r p q =
| lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q) | false |
Pulse.Checker.Bind.fst | Pulse.Checker.Bind.check_bind_fn | val check_bind_fn
(g: env)
(ctxt: vprop)
(ctxt_typing: tot_typing g ctxt tm_vprop)
(post_hint: post_hint_opt g)
(res_ppname: ppname)
(t: st_term{Tm_Bind? t.term})
(check: check_t)
: T.Tac (checker_result_t g ctxt post_hint) | val check_bind_fn
(g: env)
(ctxt: vprop)
(ctxt_typing: tot_typing g ctxt tm_vprop)
(post_hint: post_hint_opt g)
(res_ppname: ppname)
(t: st_term{Tm_Bind? t.term})
(check: check_t)
: T.Tac (checker_result_t g ctxt post_hint) | let check_bind_fn
(g:env)
(ctxt:vprop)
(ctxt_typing:tot_typing g ctxt tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(t:st_term {Tm_Bind? t.term})
(check:check_t)
: T.Tac (checker_result_t g ctxt post_hint)
= let Tm_Bind { binder; head; body } = t.term in
match head.term with
| Tm_Abs _ -> (
let (| t, c, head_typing |) = Abs.check_abs g head check in
if not (C_Tot? c)
then fail g (Some t.range) "check_bind_fn: head is not a total abstraction";
if None? post_hint
then fail g (Some t.range) "check_bind: please annotate the postcondition";
let x = fresh g in
let b = { binder with binder_ty = comp_res c } in
let g' = push_binding g x (binder.binder_ppname) b.binder_ty in
let ctxt_typing' : tot_typing g' ctxt tm_vprop =
Metatheory.tot_typing_weakening_single ctxt_typing x b.binder_ty in
let r = check g' _ ctxt_typing' post_hint res_ppname (open_st_term_nv body (binder.binder_ppname, x)) in
let body_typing = apply_checker_result_k #_ #_ #(Some?.v post_hint) r res_ppname in
let k = Pulse.Checker.Base.continuation_elaborator_with_bind_fn ctxt_typing b head_typing (binder.binder_ppname, x) in
let d = k post_hint body_typing in
checker_result_for_st_typing d res_ppname
)
| _ -> fail g (Some t.range) "check_bind_fn: head is not an abstraction" | {
"file_name": "lib/steel/pulse/Pulse.Checker.Bind.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 74,
"end_line": 63,
"start_col": 0,
"start_line": 34
} | (*
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.Checker.Bind
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Base
open Pulse.Checker.Pure
open Pulse.Checker.Prover
module T = FStar.Tactics.V2
module P = Pulse.Syntax.Printer
module Metatheory = Pulse.Typing.Metatheory
module PS = Pulse.Checker.Prover.Substs
module Abs = Pulse.Checker.Abs | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Bind.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Abs",
"short_module": "Abs"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
g: Pulse.Typing.Env.env ->
ctxt: Pulse.Syntax.Base.vprop ->
ctxt_typing: Pulse.Typing.tot_typing g ctxt Pulse.Syntax.Base.tm_vprop ->
post_hint: Pulse.Typing.post_hint_opt g ->
res_ppname: Pulse.Syntax.Base.ppname ->
t: Pulse.Syntax.Base.st_term{Tm_Bind? (Mkst_term?.term t)} ->
check: Pulse.Checker.Base.check_t
-> FStar.Tactics.Effect.Tac (Pulse.Checker.Base.checker_result_t g ctxt post_hint) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.vprop",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Typing.post_hint_opt",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.st_term",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_Tm_Bind",
"Pulse.Syntax.Base.__proj__Mkst_term__item__term",
"Pulse.Checker.Base.check_t",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.st_term'__Tm_Abs__payload",
"Pulse.Syntax.Base.comp",
"Pulse.Typing.st_typing",
"Pulse.Checker.Base.checker_result_for_st_typing",
"Pulse.Checker.Base.checker_result_t",
"Pulse.Typing.Combinators.st_typing_in_ctxt",
"Pulse.Checker.Base.continuation_elaborator",
"Pulse.Typing.Env.push_binding",
"FStar.Pervasives.Native.snd",
"Pulse.Syntax.Base.var",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ppname",
"Pulse.Syntax.Base.ppname_default",
"Pulse.Syntax.Base.comp_res",
"Pulse.Checker.Base.continuation_elaborator_with_bind_fn",
"FStar.Pervasives.Native.Some",
"Pulse.Typing.post_hint_t",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Pulse.Checker.Base.apply_checker_result_k",
"Pulse.Syntax.Naming.open_st_term_nv",
"Pulse.Typing.Metatheory.tot_typing_weakening_single",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Prims.eq2",
"FStar.Reflection.Typing.fstar_top_env",
"Pulse.Typing.Env.fstar_env",
"Pulse.Syntax.Base.Mkbinder",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_attrs",
"Prims.l_not",
"FStar.Set.mem",
"Pulse.Typing.Env.dom",
"Pulse.Typing.Env.fresh",
"Prims.unit",
"FStar.Pervasives.Native.uu___is_None",
"Pulse.Typing.Env.fail",
"Pulse.Syntax.Base.range",
"Pulse.Syntax.Base.__proj__Mkst_term__item__range",
"Prims.bool",
"Prims.op_Negation",
"Pulse.Syntax.Base.uu___is_C_Tot",
"FStar.Pervasives.dtuple3",
"Pulse.Checker.Abs.check_abs",
"Pulse.Syntax.Base.st_term'"
] | [] | false | true | false | false | false | let check_bind_fn
(g: env)
(ctxt: vprop)
(ctxt_typing: tot_typing g ctxt tm_vprop)
(post_hint: post_hint_opt g)
(res_ppname: ppname)
(t: st_term{Tm_Bind? t.term})
(check: check_t)
: T.Tac (checker_result_t g ctxt post_hint) =
| let Tm_Bind { binder = binder ; head = head ; body = body } = t.term in
match head.term with
| Tm_Abs _ ->
(let (| t , c , head_typing |) = Abs.check_abs g head check in
if not (C_Tot? c) then fail g (Some t.range) "check_bind_fn: head is not a total abstraction";
if None? post_hint then fail g (Some t.range) "check_bind: please annotate the postcondition";
let x = fresh g in
let b = { binder with binder_ty = comp_res c } in
let g' = push_binding g x (binder.binder_ppname) b.binder_ty in
let ctxt_typing':tot_typing g' ctxt tm_vprop =
Metatheory.tot_typing_weakening_single ctxt_typing x b.binder_ty
in
let r =
check g' _ ctxt_typing' post_hint res_ppname (open_st_term_nv body (binder.binder_ppname, x))
in
let body_typing = apply_checker_result_k #_ #_ #(Some?.v post_hint) r res_ppname in
let k =
Pulse.Checker.Base.continuation_elaborator_with_bind_fn ctxt_typing
b
head_typing
(binder.binder_ppname, x)
in
let d = k post_hint body_typing in
checker_result_for_st_typing d res_ppname)
| _ -> fail g (Some t.range) "check_bind_fn: head is not an abstraction" | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.lemma_witnessed_impl | val lemma_witnessed_impl (p q:mem_predicate)
:Lemma ((witnessed (fun s -> p s ==> q s) /\ witnessed p) ==> witnessed q) | val lemma_witnessed_impl (p q:mem_predicate)
:Lemma ((witnessed (fun s -> p s ==> q s) /\ witnessed p) ==> witnessed q) | let lemma_witnessed_impl p q = W.lemma_witnessed_impl mem_rel p q | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 312,
"start_col": 0,
"start_line": 312
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q)
let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p
let lemma_witnessed_nested p =
assert_norm (witnessed (fun (m:mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m:mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p);
W.lemma_witnessed_nested mem_rel p
let lemma_witnessed_and p q = W.lemma_witnessed_and mem_rel p q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.HyperStack.ST.mem_predicate -> q: FStar.HyperStack.ST.mem_predicate
-> FStar.Pervasives.Lemma
(ensures
FStar.HyperStack.ST.witnessed (fun s -> p s ==> q s) /\ FStar.HyperStack.ST.witnessed p ==>
FStar.HyperStack.ST.witnessed q) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.HyperStack.ST.mem_predicate",
"FStar.Monotonic.Witnessed.lemma_witnessed_impl",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.mem_rel",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_witnessed_impl p q =
| W.lemma_witnessed_impl mem_rel p q | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.weaken_witness | val weaken_witness (p q:mem_predicate)
:Lemma ((forall h. p h ==> q h) /\ witnessed p ==> witnessed q) | val weaken_witness (p q:mem_predicate)
:Lemma ((forall h. p h ==> q h) /\ witnessed p ==> witnessed q) | let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux () | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 265,
"start_col": 0,
"start_line": 261
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.HyperStack.ST.mem_predicate -> q: FStar.HyperStack.ST.mem_predicate
-> FStar.Pervasives.Lemma
(ensures
(forall (h: FStar.Monotonic.HyperStack.mem). p h ==> q h) /\ FStar.HyperStack.ST.witnessed p ==>
FStar.HyperStack.ST.witnessed q) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.HyperStack.ST.mem_predicate",
"FStar.Classical.move_requires",
"Prims.unit",
"Prims.l_and",
"Prims.l_Forall",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_imp",
"FStar.HyperStack.ST.witnessed",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.HyperStack.ST.lemma_functoriality"
] | [] | false | false | true | false | false | let weaken_witness p q =
| let aux () : Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q)) =
lemma_functoriality p q
in
FStar.Classical.move_requires aux () | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.lemma_witnessed_constant | val lemma_witnessed_constant (p:Type0)
:Lemma (witnessed (fun (m:mem) -> p) <==> p) | val lemma_witnessed_constant (p:Type0)
:Lemma (witnessed (fun (m:mem) -> p) <==> p) | let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 69,
"end_line": 303,
"start_col": 0,
"start_line": 303
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: Type0 -> FStar.Pervasives.Lemma (ensures FStar.HyperStack.ST.witnessed (fun _ -> p) <==> p) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Monotonic.Witnessed.lemma_witnessed_constant",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.mem_rel",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_witnessed_constant p =
| W.lemma_witnessed_constant mem_rel p | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.lemma_witnessed_or | val lemma_witnessed_or (p q:mem_predicate)
:Lemma ((witnessed p \/ witnessed q) ==> witnessed (fun s -> p s \/ q s)) | val lemma_witnessed_or (p q:mem_predicate)
:Lemma ((witnessed p \/ witnessed q) ==> witnessed (fun s -> p s \/ q s)) | let lemma_witnessed_or p q = W.lemma_witnessed_or mem_rel p q | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 61,
"end_line": 311,
"start_col": 0,
"start_line": 311
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q)
let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p
let lemma_witnessed_nested p =
assert_norm (witnessed (fun (m:mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m:mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p);
W.lemma_witnessed_nested mem_rel p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.HyperStack.ST.mem_predicate -> q: FStar.HyperStack.ST.mem_predicate
-> FStar.Pervasives.Lemma
(ensures
FStar.HyperStack.ST.witnessed p \/ FStar.HyperStack.ST.witnessed q ==>
FStar.HyperStack.ST.witnessed (fun s -> p s \/ q s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.HyperStack.ST.mem_predicate",
"FStar.Monotonic.Witnessed.lemma_witnessed_or",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.mem_rel",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_witnessed_or p q =
| W.lemma_witnessed_or mem_rel p q | false |
Simplify.fst | Simplify.simplify_expr | val simplify_expr (env: T.env_t) (e: expr) : ML expr | val simplify_expr (env: T.env_t) (e: expr) : ML expr | let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 45,
"start_col": 0,
"start_line": 31
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*) | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> e: Ast.expr -> FStar.All.ML Ast.expr | FStar.All.ML | [
"ml"
] | [] | [
"TypeSizes.env_t",
"Ast.expr",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.expr'",
"FStar.All.failwith",
"Prims.list",
"Ast.with_meta_t",
"Ast.integer_type",
"Prims.int",
"Ast.with_range",
"Ast.Constant",
"Ast.Int",
"Ast.__proj__Mkwith_meta_t__item__range",
"FStar.Pervasives.Native.option",
"Ast.either",
"Prims.bool",
"FStar.Pervasives.Native.tuple2",
"Ast.error",
"FStar.Printf.sprintf",
"Ast.print_expr",
"TypeSizes.value_of_const_expr",
"Ast.op",
"Ast.Mkwith_meta_t",
"Ast.App",
"Ast.__proj__Mkwith_meta_t__item__comments",
"FStar.List.map",
"Simplify.simplify_expr"
] | [
"recursion"
] | false | true | false | false | false | let rec simplify_expr (env: T.env_t) (e: expr) : ML expr =
| match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
(match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ ->
error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e))
e.range)
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.lemma_witnessed_nested | val lemma_witnessed_nested (p:mem_predicate)
: Lemma (witnessed (fun (m:mem) -> witnessed p) <==> witnessed p) | val lemma_witnessed_nested (p:mem_predicate)
: Lemma (witnessed (fun (m:mem) -> witnessed p) <==> witnessed p) | let lemma_witnessed_nested p =
assert_norm (witnessed (fun (m:mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m:mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p);
W.lemma_witnessed_nested mem_rel p | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 309,
"start_col": 0,
"start_line": 305
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q)
let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.HyperStack.ST.mem_predicate
-> FStar.Pervasives.Lemma
(ensures
FStar.HyperStack.ST.witnessed (fun _ -> FStar.HyperStack.ST.witnessed p) <==>
FStar.HyperStack.ST.witnessed p) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.HyperStack.ST.mem_predicate",
"FStar.Monotonic.Witnessed.lemma_witnessed_nested",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.mem_rel",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.HyperStack.ST.witnessed",
"FStar.Monotonic.Witnessed.witnessed"
] | [] | false | false | true | false | false | let lemma_witnessed_nested p =
| assert_norm (witnessed (fun (m: mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m: mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p);
W.lemma_witnessed_nested mem_rel p | false |
Simplify.fst | Simplify.simplify_atomic_action | val simplify_atomic_action (env: T.env_t) (a: atomic_action) : ML atomic_action | val simplify_atomic_action (env: T.env_t) (a: atomic_action) : ML atomic_action | let simplify_atomic_action (env:T.env_t) (a:atomic_action)
: ML atomic_action
= match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs ->
Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args)
| _ -> a | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 95,
"start_col": 0,
"start_line": 86
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata
*)
let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta} | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> a: Ast.atomic_action -> FStar.All.ML Ast.atomic_action | FStar.All.ML | [
"ml"
] | [] | [
"TypeSizes.env_t",
"Ast.atomic_action",
"Ast.expr",
"Ast.Action_return",
"Simplify.simplify_expr",
"Ast.out_expr",
"Ast.Action_assignment",
"Simplify.simplify_out_expr",
"Ast.Action_field_ptr_after",
"Ast.ident",
"Prims.list",
"Ast.Action_call",
"FStar.List.map"
] | [] | false | true | false | false | false | let simplify_atomic_action (env: T.env_t) (a: atomic_action) : ML atomic_action =
| match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs -> Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args)
| _ -> a | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.lemma_witnessed_and | val lemma_witnessed_and (p q:mem_predicate)
:Lemma (witnessed (fun s -> p s /\ q s) <==> (witnessed p /\ witnessed q)) | val lemma_witnessed_and (p q:mem_predicate)
:Lemma (witnessed (fun s -> p s /\ q s) <==> (witnessed p /\ witnessed q)) | let lemma_witnessed_and p q = W.lemma_witnessed_and mem_rel p q | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 310,
"start_col": 0,
"start_line": 310
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q)
let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p
let lemma_witnessed_nested p =
assert_norm (witnessed (fun (m:mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m:mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.HyperStack.ST.mem_predicate -> q: FStar.HyperStack.ST.mem_predicate
-> FStar.Pervasives.Lemma
(ensures
FStar.HyperStack.ST.witnessed (fun s -> p s /\ q s) <==>
FStar.HyperStack.ST.witnessed p /\ FStar.HyperStack.ST.witnessed q) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.HyperStack.ST.mem_predicate",
"FStar.Monotonic.Witnessed.lemma_witnessed_and",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.mem_rel",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_witnessed_and p q =
| W.lemma_witnessed_and mem_rel p q | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.lemma_witnessed_exists | val lemma_witnessed_exists (#t:Type) (p:(t -> mem_predicate))
:Lemma ((exists x. witnessed (p x)) ==> witnessed (fun s -> exists x. p x s)) | val lemma_witnessed_exists (#t:Type) (p:(t -> mem_predicate))
:Lemma ((exists x. witnessed (p x)) ==> witnessed (fun s -> exists x. p x s)) | let lemma_witnessed_exists #_ p = W.lemma_witnessed_exists mem_rel p | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 68,
"end_line": 314,
"start_col": 0,
"start_line": 314
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q)
let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p
let lemma_witnessed_nested p =
assert_norm (witnessed (fun (m:mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m:mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p);
W.lemma_witnessed_nested mem_rel p
let lemma_witnessed_and p q = W.lemma_witnessed_and mem_rel p q
let lemma_witnessed_or p q = W.lemma_witnessed_or mem_rel p q
let lemma_witnessed_impl p q = W.lemma_witnessed_impl mem_rel p q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: (_: t -> FStar.HyperStack.ST.mem_predicate)
-> FStar.Pervasives.Lemma
(ensures
(exists (x: t). FStar.HyperStack.ST.witnessed (p x)) ==>
FStar.HyperStack.ST.witnessed (fun s -> exists (x: t). p x s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.HyperStack.ST.mem_predicate",
"FStar.Monotonic.Witnessed.lemma_witnessed_exists",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.mem_rel",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_witnessed_exists #_ p =
| W.lemma_witnessed_exists mem_rel p | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.lemma_witnessed_forall | val lemma_witnessed_forall (#t:Type) (p:(t -> mem_predicate))
:Lemma ((witnessed (fun s -> forall x. p x s)) <==> (forall x. witnessed (p x))) | val lemma_witnessed_forall (#t:Type) (p:(t -> mem_predicate))
:Lemma ((witnessed (fun s -> forall x. p x s)) <==> (forall x. witnessed (p x))) | let lemma_witnessed_forall #_ p = W.lemma_witnessed_forall mem_rel p | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 68,
"end_line": 313,
"start_col": 0,
"start_line": 313
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q)
let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p
let lemma_witnessed_nested p =
assert_norm (witnessed (fun (m:mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m:mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p);
W.lemma_witnessed_nested mem_rel p
let lemma_witnessed_and p q = W.lemma_witnessed_and mem_rel p q
let lemma_witnessed_or p q = W.lemma_witnessed_or mem_rel p q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: (_: t -> FStar.HyperStack.ST.mem_predicate)
-> FStar.Pervasives.Lemma
(ensures
FStar.HyperStack.ST.witnessed (fun s -> forall (x: t). p x s) <==>
(forall (x: t). FStar.HyperStack.ST.witnessed (p x))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.HyperStack.ST.mem_predicate",
"FStar.Monotonic.Witnessed.lemma_witnessed_forall",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.mem_rel",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_witnessed_forall #_ p =
| W.lemma_witnessed_forall mem_rel p | false |
Simplify.fst | Simplify.simplify_prog | val simplify_prog (benv:B.global_env) (senv:TypeSizes.size_env) (p:list decl) : ML (list decl) | val simplify_prog (benv:B.global_env) (senv:TypeSizes.size_env) (p:list decl) : ML (list decl) | let simplify_prog benv senv (p:list decl) =
List.map (simplify_decl (B.mk_env benv, senv)) p | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 50,
"end_line": 199,
"start_col": 0,
"start_line": 198
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata
*)
let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta}
let simplify_atomic_action (env:T.env_t) (a:atomic_action)
: ML atomic_action
= match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs ->
Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args)
| _ -> a //action mutable identifiers are not subject to substitution
let rec simplify_action (env:T.env_t) (a:action) : ML action =
match a.v with
| Atomic_action aa -> {a with v = Atomic_action (simplify_atomic_action env aa)}
| Action_seq hd tl -> {a with v = Action_seq (simplify_atomic_action env hd) (simplify_action env tl) }
| Action_ite hd then_ else_ -> {a with v = Action_ite (simplify_expr env hd) (simplify_action env then_) (simplify_action_opt env else_) }
| Action_let i aa k -> {a with v = Action_let i (simplify_atomic_action env aa) (simplify_action env k) }
| Action_act a -> { a with v = Action_act (simplify_action env a) }
and simplify_action_opt (env:T.env_t) (a:option action) : ML (option action) =
match a with
| None -> None
| Some a -> Some (simplify_action env a)
let simplify_field_array (env:T.env_t) (f:field_array_t) : ML field_array_t =
match f with
| FieldScalar -> FieldScalar
| FieldArrayQualified (e, b) -> FieldArrayQualified (simplify_expr env e, b)
| FieldString sz -> FieldString (map_opt (simplify_expr env) sz)
| FieldConsumeAll -> FieldConsumeAll
let simplify_atomic_field (env:T.env_t) (f:atomic_field)
: ML atomic_field
= let sf = f.v in
let ft = simplify_typ env sf.field_type in
let fa = simplify_field_array env sf.field_array_opt in
let fc = sf.field_constraint |> map_opt (simplify_expr env) in
let fact =
match sf.field_action with
| None -> None
| Some (a, b) -> Some (simplify_action env a, b)
in
let sf = { sf with field_type = ft;
field_array_opt = fa;
field_constraint = fc;
field_action = fact } in
{ f with v = sf }
let rec simplify_field (env:T.env_t) (f:field)
: ML field
= match f.v with
| AtomicField af -> { f with v = AtomicField (simplify_atomic_field env af) }
| RecordField fs i -> { f with v = RecordField (List.map (simplify_field env) fs) i }
| SwitchCaseField swc i -> { f with v = SwitchCaseField (simplify_switch_case env swc) i }
and simplify_switch_case (env:T.env_t) (c:switch_case)
: ML switch_case =
let (e, cases) = c in
let e = simplify_expr env e in
let cases =
List.map
(function Case e f -> Case (simplify_expr env e) (simplify_field env f)
| DefaultCase f -> DefaultCase (simplify_field env f))
cases
in
e, cases
let rec simplify_out_fields (env:T.env_t) (flds:list out_field) : ML (list out_field) =
List.map (fun fld -> match fld with
| Out_field_named id t n -> Out_field_named id (simplify_typ env t) n
| Out_field_anon flds is_union ->
Out_field_anon (simplify_out_fields env flds) is_union) flds
let simplify_decl (env:T.env_t) (d:decl) : ML decl =
match d.d_decl.v with
| ModuleAbbrev _ _ -> d
| Define i None c -> d
| Define i (Some t) c -> decl_with_v d (Define i (Some (simplify_typ env t)) c)
| TypeAbbrev t i ->
let t' = simplify_typ env t in
B.update_typ_abbrev (fst env) i t';
decl_with_v d (TypeAbbrev t' i)
| Enum t i cases ->
let t = simplify_typ env t in
decl_with_v d (Enum t i cases)
| Record tdnames params wopt fields ->
let params = List.map (fun (t, i, q) -> simplify_typ env t, i, q) params in
let fields = List.map (simplify_field env) fields in
let wopt = match wopt with | None -> None | Some w -> Some (simplify_expr env w) in
decl_with_v d (Record tdnames params wopt fields)
| CaseType tdnames params switch ->
let params = List.map (fun (t, i, q) -> simplify_typ env t, i, q) params in
let switch = simplify_switch_case env switch in
decl_with_v d (CaseType tdnames params switch)
| OutputType out_t ->
decl_with_v d (OutputType ({out_t with out_typ_fields=simplify_out_fields env out_t.out_typ_fields}))
| ExternType tdnames -> d
| ExternFn f ret params ->
let ret = simplify_typ env ret in
let params = List.map (fun (t, i, q) -> simplify_typ env t, i, q) params in
decl_with_v d (ExternFn f ret params)
| ExternProbe _ -> d | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | benv: GlobalEnv.global_env -> senv: TypeSizes.size_env -> p: Prims.list Ast.decl
-> FStar.All.ML (Prims.list Ast.decl) | FStar.All.ML | [
"ml"
] | [] | [
"GlobalEnv.global_env",
"TypeSizes.size_env",
"Prims.list",
"Ast.decl",
"FStar.List.map",
"Simplify.simplify_decl",
"TypeSizes.env_t",
"FStar.Pervasives.Native.Mktuple2",
"Binding.env",
"Binding.mk_env"
] | [] | false | true | false | false | false | let simplify_prog benv senv (p: list decl) =
| List.map (simplify_decl (B.mk_env benv, senv)) p | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.free_drgn | val free_drgn (d:drgn)
: ST unit
(requires fun m -> contains_region m (rid_of_drgn d))
(ensures fun m0 _ m1 -> m1 == HS.free_heap_region m0 (rid_of_drgn d)) | val free_drgn (d:drgn)
: ST unit
(requires fun m -> contains_region m (rid_of_drgn d))
(ensures fun m0 _ m1 -> m1 == HS.free_heap_region m0 (rid_of_drgn d)) | let free_drgn d =
let m0 = gst_get () in
let m1 = HS.free_heap_region m0 d in
gst_put m1 | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 12,
"end_line": 332,
"start_col": 0,
"start_line": 329
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q)
let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p
let lemma_witnessed_nested p =
assert_norm (witnessed (fun (m:mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m:mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p);
W.lemma_witnessed_nested mem_rel p
let lemma_witnessed_and p q = W.lemma_witnessed_and mem_rel p q
let lemma_witnessed_or p q = W.lemma_witnessed_or mem_rel p q
let lemma_witnessed_impl p q = W.lemma_witnessed_impl mem_rel p q
let lemma_witnessed_forall #_ p = W.lemma_witnessed_forall mem_rel p
let lemma_witnessed_exists #_ p = W.lemma_witnessed_exists mem_rel p
let drgn = d_hrid
let rid_of_drgn d = d
let new_drgn r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_freeable_heap_region m0 r0 in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: FStar.HyperStack.ST.drgn -> FStar.HyperStack.ST.ST Prims.unit | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.HyperStack.ST.drgn",
"FStar.HyperStack.ST.gst_put",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.Monotonic.HyperStack.free_heap_region",
"FStar.HyperStack.ST.gst_get"
] | [] | false | true | false | false | false | let free_drgn d =
| let m0 = gst_get () in
let m1 = HS.free_heap_region m0 d in
gst_put m1 | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.ralloc_drgn | val ralloc_drgn (#a:Type) (#rel:preorder a) (d:drgn) (init:a)
: ST (mreference a rel)
(requires fun m -> m `contains_region` (rid_of_drgn d))
(ensures fun m0 r m1 ->
not (HS.is_mm r) /\
ralloc_post (rid_of_drgn d) init m0 r m1) | val ralloc_drgn (#a:Type) (#rel:preorder a) (d:drgn) (init:a)
: ST (mreference a rel)
(requires fun m -> m `contains_region` (rid_of_drgn d))
(ensures fun m0 r m1 ->
not (HS.is_mm r) /\
ralloc_post (rid_of_drgn d) init m0 r m1) | let ralloc_drgn #_ #_ d init = ralloc_common (rid_of_drgn d) init false | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 71,
"end_line": 334,
"start_col": 0,
"start_line": 334
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q)
let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p
let lemma_witnessed_nested p =
assert_norm (witnessed (fun (m:mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m:mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p);
W.lemma_witnessed_nested mem_rel p
let lemma_witnessed_and p q = W.lemma_witnessed_and mem_rel p q
let lemma_witnessed_or p q = W.lemma_witnessed_or mem_rel p q
let lemma_witnessed_impl p q = W.lemma_witnessed_impl mem_rel p q
let lemma_witnessed_forall #_ p = W.lemma_witnessed_forall mem_rel p
let lemma_witnessed_exists #_ p = W.lemma_witnessed_exists mem_rel p
let drgn = d_hrid
let rid_of_drgn d = d
let new_drgn r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_freeable_heap_region m0 r0 in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let free_drgn d =
let m0 = gst_get () in
let m1 = HS.free_heap_region m0 d in
gst_put m1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: FStar.HyperStack.ST.drgn -> init: a
-> FStar.HyperStack.ST.ST (FStar.HyperStack.ST.mreference a rel) | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Preorder.preorder",
"FStar.HyperStack.ST.drgn",
"FStar.HyperStack.ST.ralloc_common",
"FStar.HyperStack.ST.rid_of_drgn",
"FStar.HyperStack.ST.mreference"
] | [] | false | true | false | false | false | let ralloc_drgn #_ #_ d init =
| ralloc_common (rid_of_drgn d) init false | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.ralloc_drgn_mm | val ralloc_drgn_mm (#a:Type) (#rel:preorder a) (d:drgn) (init:a)
: ST (mreference a rel)
(requires fun m -> m `contains_region` (rid_of_drgn d))
(ensures fun m0 r m1 ->
HS.is_mm r /\
ralloc_post (rid_of_drgn d) init m0 r m1) | val ralloc_drgn_mm (#a:Type) (#rel:preorder a) (d:drgn) (init:a)
: ST (mreference a rel)
(requires fun m -> m `contains_region` (rid_of_drgn d))
(ensures fun m0 r m1 ->
HS.is_mm r /\
ralloc_post (rid_of_drgn d) init m0 r m1) | let ralloc_drgn_mm #_ #_ d init = ralloc_common (rid_of_drgn d) init true | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 73,
"end_line": 335,
"start_col": 0,
"start_line": 335
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q)
let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p
let lemma_witnessed_nested p =
assert_norm (witnessed (fun (m:mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m:mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p);
W.lemma_witnessed_nested mem_rel p
let lemma_witnessed_and p q = W.lemma_witnessed_and mem_rel p q
let lemma_witnessed_or p q = W.lemma_witnessed_or mem_rel p q
let lemma_witnessed_impl p q = W.lemma_witnessed_impl mem_rel p q
let lemma_witnessed_forall #_ p = W.lemma_witnessed_forall mem_rel p
let lemma_witnessed_exists #_ p = W.lemma_witnessed_exists mem_rel p
let drgn = d_hrid
let rid_of_drgn d = d
let new_drgn r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_freeable_heap_region m0 r0 in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let free_drgn d =
let m0 = gst_get () in
let m1 = HS.free_heap_region m0 d in
gst_put m1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: FStar.HyperStack.ST.drgn -> init: a
-> FStar.HyperStack.ST.ST (FStar.HyperStack.ST.mreference a rel) | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Preorder.preorder",
"FStar.HyperStack.ST.drgn",
"FStar.HyperStack.ST.ralloc_common",
"FStar.HyperStack.ST.rid_of_drgn",
"FStar.HyperStack.ST.mreference"
] | [] | false | true | false | false | false | let ralloc_drgn_mm #_ #_ d init =
| ralloc_common (rid_of_drgn d) init true | false |
FStar.HyperStack.ST.fst | FStar.HyperStack.ST.new_drgn | val new_drgn (r0:rid)
: ST drgn
(requires fun m -> is_eternal_region r0)
(ensures fun m0 d m1 ->
let r1 = rid_of_drgn d in
new_region_post_common r0 r1 m0 m1 /\
HS.color r1 == HS.color r0 /\
(r1, m1) == HS.new_freeable_heap_region m0 r0) | val new_drgn (r0:rid)
: ST drgn
(requires fun m -> is_eternal_region r0)
(ensures fun m0 d m1 ->
let r1 = rid_of_drgn d in
new_region_post_common r0 r1 m0 m1 /\
HS.color r1 == HS.color r0 /\
(r1, m1) == HS.new_freeable_heap_region m0 r0) | let new_drgn r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_freeable_heap_region m0 r0 in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid | {
"file_name": "ulib/FStar.HyperStack.ST.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 327,
"start_col": 0,
"start_line": 320
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack.ST
open FStar.HyperStack
module W = FStar.Monotonic.Witnessed
module HS = FStar.HyperStack
open FStar.Preorder
(* Eternal regions remain contained *)
private let eternal_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (HS.is_heap_color (color r)); (m1 `contains_region` r)}
(HS.is_eternal_region_hs r /\ m1 `contains_region` r) ==> m2 `contains_region` r
(* rid counter increases monotonically *)
private let rid_ctr_pred (m1 m2:mem) :Type0 = get_rid_ctr m1 <= get_rid_ctr m2
(*
* A region r, that is:
* (a) not contained in m1, and
* (b) has rid last component less than m1.rid_ctr
*
* remains not contained in m2
*)
private let rid_last_component_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
((~ (m1 `contains_region` r)) /\ rid_last_component r < get_rid_ctr m1) ==>
(~ (m2 `contains_region` r))
(* Predicate for eternal refs *)
private let eternal_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).
{:pattern (m1 `HS.contains` r)}
(is_mm r) \/
(((m1 `HS.contains` r) /\
(HS.is_eternal_region_hs (frameOf r) \/
m2 `contains_region` (HS.frameOf r))) ==> (m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r)))
(*
* Predicate for next ref address in a region's heap
* For all regions, their next_addr increases monotonically (or the region ceases to exist)
*)
private let next_ref_addr_in_a_region_pred (m1 m2:mem) :Type0
= forall (r:HS.rid).{:pattern (m1 `contains_region` r)}
(m1 `contains_region` r) ==>
(if m2 `contains_region` r then
let h1 = Map.sel (HS.get_hmap m1) r in
let h2 = Map.sel (HS.get_hmap m2) r in
Heap.next_addr h1 <= Heap.next_addr h2
else True)
(* Predicate that an unused ref whose addr is less than the next addr remains unused *)
private let unused_ref_next_addr_pred (m1 m2:mem) :Type0
= forall (rid:HS.rid).{:pattern (m1 `contains_region` rid)}
(m1 `contains_region` rid) ==>
(let h1 = Map.sel (HS.get_hmap m1) rid in
(forall (a:Type0) (rel:preorder a) (r:HS.mreference a rel).{:pattern (r `HS.unused_in` m1)}
(HS.frameOf r == rid /\ r `HS.unused_in` m1 /\ HS.as_addr r < Heap.next_addr h1) ==>
(r `HS.unused_in` m2)))
(* Predicate for mm refs *)
private let mm_refs_pred (m1 m2:mem) :Type0
= forall (a:Type) (rel:preorder a) (r:HS.mreference a rel).{:pattern (m1 `HS.contains` r)}
(not (is_mm r)) \/
(m1 `HS.contains` r ==>
(m2 `HS.contains` r /\ rel (HS.sel m1 r) (HS.sel m2 r) \/
r `HS.unused_in` m2))
(* The preorder is the conjunction of above predicates *)
let mem_rel :preorder mem
= HS.lemma_rid_ctr_pred (); HS.lemma_next_addr_contained_refs_addr ();
fun (m1 m2:mem) ->
eternal_region_pred m1 m2 /\ rid_ctr_pred m1 m2 /\ rid_last_component_pred m1 m2 /\ eternal_refs_pred m1 m2 /\
next_ref_addr_in_a_region_pred m1 m2 /\ unused_ref_next_addr_pred m1 m2 /\ mm_refs_pred m1 m2
(* Predicates that we will witness with regions and refs *)
let region_contains_pred r =
fun m -> (not (HS.is_eternal_region_hs r)) \/ m `contains_region` r
let ref_contains_pred #_ #_ r =
fun m ->
let rid = HS.frameOf r in
rid_last_component rid < get_rid_ctr m /\
(m `contains_region` rid ==> (
(HS.as_addr r < Heap.next_addr (Map.sel (HS.get_hmap m) rid)) /\
(HS.is_mm r ==> (m `HS.contains` r \/ r `HS.unused_in` m)) /\
((not (HS.is_mm r)) ==> m `HS.contains` r)))
let stable p = forall (h1:mem) (h2:mem).{:pattern (mem_rel h1 h2)} (p h1 /\ mem_rel h1 h2) ==> p h2
let witnessed p = W.witnessed mem_rel p
(* TODO: we should derive these using DM4F *)
let gst_get _ = admit ()
let gst_put _ = admit ()
let gst_witness _ = admit ()
let gst_recall _ = admit ()
let lemma_functoriality p q = W.lemma_witnessed_weakening mem_rel p q
let same_refs_in_all_regions m0 m1 = same_refs_common contained_region m0 m1
let same_refs_in_stack_regions m0 m1 = same_refs_common contained_stack_region m0 m1
let same_refs_in_non_tip_regions m0 m1 = same_refs_common contained_non_tip_region m0 m1
let same_refs_in_non_tip_stack_regions m0 m1 = same_refs_common contained_non_tip_stack_region m0 m1
let lemma_same_refs_in_all_regions_intro _ _ = ()
let lemma_same_refs_in_all_regions_elim _ _ _ = ()
let lemma_same_refs_in_stack_regions_intro _ _ = ()
let lemma_same_refs_in_stack_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_regions_elim _ _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_intro _ _ = ()
let lemma_same_refs_in_non_tip_stack_regions_elim _ _ _ = ()
let lemma_equal_domains_trans _ _ _ = ()
let push_frame _ =
let m0 = gst_get () in
let m1 = HS.hs_push_frame m0 in
gst_put m1
let pop_frame _ =
let m1 = pop (gst_get ()) in
gst_put m1
private let salloc_common (#a:Type) (#rel:preorder a) (init:a) (mm:bool)
:StackInline (mreference a rel)
(requires (fun m -> is_stack_region (get_tip m)))
(ensures (fun m0 s m1 -> is_stack_region (HS.frameOf s) /\ salloc_post init m0 s m1 /\ is_mm s == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel (get_tip m0) init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (get_hmap m0) (get_tip m0)) init mm; //AR: to prove that next_addr in tip's heap increases (it is part of mem_rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred (); //AR: to prove that rid_last_component of r.id is < rid_ctr
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred (HS.frameOf r));
r
let salloc #_ #_ init = salloc_common init false
let salloc_mm #_ #_ init = salloc_common init true
let sfree #_ #_ r =
let m0 = gst_get () in
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.get_tip m0)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let new_region r0 =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 None in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
let new_colored_region r0 c =
if r0 <> HS.root then gst_recall (region_contains_pred r0); //recall containment of r0
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_eternal_region m0 r0 (Some c) in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid
private let ralloc_common (#a:Type) (#rel:preorder a) (i:rid) (init:a) (mm:bool)
:ST (mreference a rel)
(requires (fun m -> is_heap_color (color i) /\ m `contains_region` i))
(ensures (fun m0 r m1 -> ralloc_post i init m0 r m1 /\ is_mm r == mm))
= let m0 = gst_get () in
let r, m1 = HS.alloc rel i init mm m0 in
Heap.lemma_next_addr_alloc rel (Map.sel (HS.get_hmap m0) i) init mm; //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1;
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
HS.lemma_rid_ctr_pred ();
gst_witness (ref_contains_pred r);
gst_witness (region_contains_pred i);
r
let ralloc #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init false
let ralloc_mm #_ #_ i init =
if i <> HS.root then gst_recall (region_contains_pred i);
ralloc_common i init true
let rfree #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
HS.lemma_rid_ctr_pred ();
let m1 = HS.free r m0 in
assert (Set.equal (Map.domain (get_hmap m0)) (Map.domain (get_hmap m1)));
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_next_addr_free_mm (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r); //AR: to prove that next_addr in tip's heap remains same (to satisfy the predicate in mm rel)
gst_put m1
let op_Colon_Equals #_ #_ r v =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
let m1 = HS.upd_tot m0 r v in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
Heap.lemma_upd_equals_upd_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r) v;
Heap.lemma_next_addr_upd (Map.sel (HS.get_hmap m0) (HS.frameOf r)) (HS.as_ref r) v; //next_addr in ref's rid heap remains same
gst_put m1
let op_Bang #_ #_ r =
let m0 = gst_get () in
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (ref_contains_pred r);
Heap.lemma_sel_equals_sel_tot_for_contained_refs (get_hmap m0 `Map.sel` (HS.frameOf r)) (HS.as_ref r);
HS.sel_tot m0 r
let get _ = gst_get ()
let recall #_ #_ r =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r))
let recall_region i = if i <> HS.root then gst_recall (region_contains_pred i)
let witness_region i = gst_witness (region_contains_pred i)
let witness_hsref #_ #_ r =
HS.lemma_rid_ctr_pred ();
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (ref_contains_pred r)
let mr_witness #r #_ #_ m p =
recall m;
let p_pred (#i:erid) (#a:Type) (#b:preorder a)
(r:m_rref i a b) (p:mem_predicate)
:mem_predicate
= fun m -> m `contains` r /\ p m
in
gst_witness (p_pred m p);
lemma_functoriality (p_pred m p) p
let weaken_witness p q =
let aux () :Lemma (requires ((forall h. p h ==> q h) /\ witnessed p)) (ensures (witnessed q))
= lemma_functoriality p q
in
FStar.Classical.move_requires aux ()
let testify (p:mem_predicate) = gst_recall p
let testify_forall #c #p $s =
W.lemma_witnessed_forall mem_rel p;
gst_recall (fun h -> forall (x:c). p x h)
let testify_forall_region_contains_pred #c #p $s =
let p' (x:c) :mem_predicate = region_contains_pred (p x) in
let s:squash (forall (x:c). witnessed (p' x)) = () in
testify_forall s
private let mem_rel_predicate (#a:Type0) (#rel:preorder a) (r:mreference a rel) (p:mem_predicate)
:mem_predicate
= let rid = HS.frameOf r in
fun m ->
(HS.rid_last_component rid < HS.get_rid_ctr m) /\ ( //will help us prove that a deallocated region remains deallocated
(m `HS.contains` r /\ p m) \/ //the ref is contained and satisfies p
(m `contains_region` rid /\ ~ (m `HS.contains_ref_in_its_region` r) /\ HS.as_addr r < Heap.next_addr (HS.get_hmap m `Map.sel` rid) /\ r `HS.unused_in` m) \/ //the ref is deallocated, but its region is contained and next_addr > addr_of ref
(not (m `contains_region` rid))) //the region itself is not there
let token_p #_ #_ r p = witnessed (mem_rel_predicate r p)
let witness_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
HS.lemma_next_addr_contained_refs_addr ();
gst_witness (mem_rel_predicate r p)
let recall_p #_ #_ r p =
gst_recall (ref_contains_pred r);
gst_recall (region_contains_pred (HS.frameOf r));
gst_recall (mem_rel_predicate r p)
let token_functoriality #_ #_ r p q =
lemma_functoriality (mem_rel_predicate r p) (mem_rel_predicate r q)
let lemma_witnessed_constant p = W.lemma_witnessed_constant mem_rel p
let lemma_witnessed_nested p =
assert_norm (witnessed (fun (m:mem) -> witnessed p) ==
W.witnessed mem_rel (fun (m:mem) -> W.witnessed mem_rel p));
assert_norm (witnessed p == W.witnessed mem_rel p);
W.lemma_witnessed_nested mem_rel p
let lemma_witnessed_and p q = W.lemma_witnessed_and mem_rel p q
let lemma_witnessed_or p q = W.lemma_witnessed_or mem_rel p q
let lemma_witnessed_impl p q = W.lemma_witnessed_impl mem_rel p q
let lemma_witnessed_forall #_ p = W.lemma_witnessed_forall mem_rel p
let lemma_witnessed_exists #_ p = W.lemma_witnessed_exists mem_rel p
let drgn = d_hrid
let rid_of_drgn d = d | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.HyperStack.ST.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r0: FStar.Monotonic.HyperHeap.rid -> FStar.HyperStack.ST.ST FStar.HyperStack.ST.drgn | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.drgn",
"Prims.unit",
"FStar.HyperStack.ST.gst_witness",
"FStar.HyperStack.ST.region_contains_pred",
"FStar.HyperStack.ST.gst_put",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"FStar.Monotonic.HyperStack.fresh_region",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Prims.b2t",
"FStar.Monotonic.HyperHeap.rid_freeable",
"FStar.Monotonic.HyperStack.new_freeable_heap_region",
"FStar.HyperStack.ST.gst_get",
"FStar.Monotonic.HyperStack.lemma_rid_ctr_pred",
"Prims.op_disEquality",
"FStar.Monotonic.HyperHeap.root",
"FStar.HyperStack.ST.gst_recall",
"Prims.bool"
] | [] | false | true | false | false | false | let new_drgn r0 =
| if r0 <> HS.root then gst_recall (region_contains_pred r0);
HS.lemma_rid_ctr_pred ();
let m0 = gst_get () in
let new_rid, m1 = HS.new_freeable_heap_region m0 r0 in
gst_put m1;
gst_witness (region_contains_pred new_rid);
new_rid | false |
ZetaHashAccumulator.fst | ZetaHashAccumulator.bytes | val bytes : Type0 | let bytes = Seq.seq U8.t | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 56,
"start_col": 0,
"start_line": 56
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.UInt8.t"
] | [] | false | false | false | true | true | let bytes =
| Seq.seq U8.t | false |
|
ZetaHashAccumulator.fst | ZetaHashAccumulator.e_raw_hash_value_t | val e_raw_hash_value_t : Type0 | let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32} | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 70,
"end_line": 68,
"start_col": 0,
"start_line": 68
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"FStar.UInt8.t",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Ghost.reveal"
] | [] | false | false | false | true | true | let e_raw_hash_value_t =
| l: erased (Seq.seq U8.t) {Seq.length l == 32} | false |
|
ZetaHashAccumulator.fst | ZetaHashAccumulator.u32_to_u64 | val u32_to_u64 (x: U32.t) : U64.t | val u32_to_u64 (x: U32.t) : U64.t | let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 58,
"end_line": 54,
"start_col": 0,
"start_line": 54
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt32.t -> FStar.UInt64.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"FStar.Int.Cast.uint32_to_uint64",
"FStar.UInt64.t"
] | [] | false | false | false | true | false | let u32_to_u64 (x: U32.t) : U64.t =
| Cast.uint32_to_uint64 x | false |
ZetaHashAccumulator.fst | ZetaHashAccumulator.raw_hash_value_t | val raw_hash_value_t : Type0 | let raw_hash_value_t = Seq.lseq U8.t 32 | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 39,
"end_line": 67,
"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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length } | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t"
] | [] | false | false | false | true | true | let raw_hash_value_t =
| Seq.lseq U8.t 32 | false |
|
Simplify.fst | Simplify.simplify_atomic_field | val simplify_atomic_field (env: T.env_t) (f: atomic_field) : ML atomic_field | val simplify_atomic_field (env: T.env_t) (f: atomic_field) : ML atomic_field | let simplify_atomic_field (env:T.env_t) (f:atomic_field)
: ML atomic_field
= let sf = f.v in
let ft = simplify_typ env sf.field_type in
let fa = simplify_field_array env sf.field_array_opt in
let fc = sf.field_constraint |> map_opt (simplify_expr env) in
let fact =
match sf.field_action with
| None -> None
| Some (a, b) -> Some (simplify_action env a, b)
in
let sf = { sf with field_type = ft;
field_array_opt = fa;
field_constraint = fc;
field_action = fact } in
{ f with v = sf } | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 21,
"end_line": 131,
"start_col": 0,
"start_line": 116
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata
*)
let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta}
let simplify_atomic_action (env:T.env_t) (a:atomic_action)
: ML atomic_action
= match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs ->
Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args)
| _ -> a //action mutable identifiers are not subject to substitution
let rec simplify_action (env:T.env_t) (a:action) : ML action =
match a.v with
| Atomic_action aa -> {a with v = Atomic_action (simplify_atomic_action env aa)}
| Action_seq hd tl -> {a with v = Action_seq (simplify_atomic_action env hd) (simplify_action env tl) }
| Action_ite hd then_ else_ -> {a with v = Action_ite (simplify_expr env hd) (simplify_action env then_) (simplify_action_opt env else_) }
| Action_let i aa k -> {a with v = Action_let i (simplify_atomic_action env aa) (simplify_action env k) }
| Action_act a -> { a with v = Action_act (simplify_action env a) }
and simplify_action_opt (env:T.env_t) (a:option action) : ML (option action) =
match a with
| None -> None
| Some a -> Some (simplify_action env a)
let simplify_field_array (env:T.env_t) (f:field_array_t) : ML field_array_t =
match f with
| FieldScalar -> FieldScalar
| FieldArrayQualified (e, b) -> FieldArrayQualified (simplify_expr env e, b)
| FieldString sz -> FieldString (map_opt (simplify_expr env) sz)
| FieldConsumeAll -> FieldConsumeAll | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> f: Ast.atomic_field -> FStar.All.ML Ast.atomic_field | FStar.All.ML | [
"ml"
] | [] | [
"TypeSizes.env_t",
"Ast.atomic_field",
"Ast.Mkwith_meta_t",
"Ast.atomic_field'",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Ast.Mkatomic_field'",
"Ast.__proj__Mkatomic_field'__item__field_dependence",
"Ast.__proj__Mkatomic_field'__item__field_ident",
"Ast.__proj__Mkatomic_field'__item__field_bitwidth",
"Ast.__proj__Mkatomic_field'__item__field_probe",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Ast.action",
"Prims.bool",
"Ast.__proj__Mkatomic_field'__item__field_action",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"Simplify.simplify_action",
"Ast.expr",
"Ast.map_opt",
"Simplify.simplify_expr",
"Ast.__proj__Mkatomic_field'__item__field_constraint",
"Ast.field_array_t",
"Simplify.simplify_field_array",
"Ast.__proj__Mkatomic_field'__item__field_array_opt",
"Ast.typ",
"Simplify.simplify_typ",
"Ast.__proj__Mkatomic_field'__item__field_type",
"Ast.__proj__Mkwith_meta_t__item__v"
] | [] | false | true | false | false | false | let simplify_atomic_field (env: T.env_t) (f: atomic_field) : ML atomic_field =
| let sf = f.v in
let ft = simplify_typ env sf.field_type in
let fa = simplify_field_array env sf.field_array_opt in
let fc = sf.field_constraint |> map_opt (simplify_expr env) in
let fact =
match sf.field_action with
| None -> None
| Some (a, b) -> Some (simplify_action env a, b)
in
let sf =
{ sf with field_type = ft; field_array_opt = fa; field_constraint = fc; field_action = fact }
in
{ f with v = sf } | false |
ZetaHashAccumulator.fst | ZetaHashAccumulator.hashable_buffer | val hashable_buffer : Type0 | let hashable_buffer = b:A.array U8.t { A.length b ≤ blake2_max_input_length } | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 77,
"end_line": 152,
"start_col": 0,
"start_line": 152
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32}
// A hash value is a pair of a (cumulative) hash and a counter
let hash_value_t =
raw_hash_value_t &
ℕ
let initial_hash
: hash_value_t
= Seq.create 32 0uy, 0
// We just assume a spec for Blake, rather than connecting with the actual HACL code
assume
val blake_spec (d:Seq.seq U8.t { Seq.length d <= blake2_max_input_length})
: out:Seq.seq U8.t { Seq.length out == 32 }
// Hashing a single value just calls Blake and sets the counter to 1
let hash_one_value (s:Seq.seq U8.t { Seq.length s ≤ blake2_max_input_length })
: hash_value_t
= blake_spec s, 1
// Hash accumulation is by XOR
let xor_bytes (s1:bytes) (s2:bytes { Seq.length s1 == Seq.length s2 }) : bytes
= Seq.init (Seq.length s1)
(λ i → Seq.index s1 i `FStar.UInt8.logxor` Seq.index s2 i)
// A version (useful for induction) of xor_bytes that only XORs the first i bytes
// In Zeta, i is requires to be less than the length of the s1
// But, here, I "overdefine" the function, which makes it a bit easier to use
// in aggregate_raw_hashes.
// We should also try to make the version with the refinement on i work
let xor_bytes_pfx (s1:bytes)
(s2:bytes { Seq.length s1 == Seq.length s2 })
(i:ℕ)
: bytes
= let i = if i > Seq.length s1 then Seq.length s1 else i in
Seq.append
(xor_bytes (Seq.slice s1 0 i) (Seq.slice s2 0 i))
(Seq.slice s1 i (Seq.length s1))
// A lemma that says that if we XOR the first i bytes of two sequences, and then
// XOR the i-th byte, we get the same result as XORing the first (i+1) bytes
let extend_hash_value (s1 s2:bytes)
(i:ℕ)
: Lemma (requires Seq.length s1 == Seq.length s2 ∧
i < Seq.length s1)
(ensures Seq.upd (xor_bytes_pfx s1 s2 i)
i
(U8.logxor (Seq.index s1 i) (Seq.index s2 i))
`Seq.equal`
xor_bytes_pfx s1 s2 (i + 1))
= ()
// Aggregating two hashes is just XORing the two hashes and adding the counters
let aggregate_hashes (h0 h1: hash_value_t)
: hash_value_t
= xor_bytes (fst h0) (fst h1),
snd h0 + snd h1
(* END Pure Spec *)
(***************************************************************)
(* Model of HACL's blake2b *)
assume
val blake2b:
nn:SZ.t{1 ≤ SZ.v nn ∧ SZ.v nn ≤ 64}
-> output: A.array U8.t { A.length output == SZ.v nn}
-> ll: SZ.t { SZ.v ll <= blake2_max_input_length}
-> d:A.array U8.t { SZ.v ll ≤ A.length d}
-> kk: SZ.t { kk == 0sz } //We do not use blake2 in keyed mode
-> _dummy: A.array U8.t // this really should be a NULL, but krml doesn't extract Steel's null pointers yet
-> #sout:Ghost.erased (Seq.lseq U8.t 32)
-> #p:perm
-> #sd:Ghost.erased (Seq.seq U8.t) { Seq.length sd == SZ.v ll}
-> stt unit
(A.pts_to output sout ** A.pts_to d #p sd)
(λ _ → A.pts_to output (blake_spec (Seq.slice sd 0 (SZ.v ll)))
**
A.pts_to d #p sd)
(***************************************************************)
(* Pulse *) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.Array.Core.array",
"FStar.UInt8.t",
"Prims.b2t",
"Pulse.Lib.BoundedIntegers.op_Less_Equals",
"Prims.int",
"Pulse.Lib.BoundedIntegers.bounded_int_int",
"Pulse.Lib.Array.Core.length",
"ZetaHashAccumulator.blake2_max_input_length"
] | [] | false | false | false | true | true | let hashable_buffer =
| b: A.array U8.t {A.length b <= blake2_max_input_length} | false |
|
Simplify.fst | Simplify.simplify_action | val simplify_action (env: T.env_t) (a: action) : ML action | val simplify_action (env: T.env_t) (a: action) : ML action | let rec simplify_action (env:T.env_t) (a:action) : ML action =
match a.v with
| Atomic_action aa -> {a with v = Atomic_action (simplify_atomic_action env aa)}
| Action_seq hd tl -> {a with v = Action_seq (simplify_atomic_action env hd) (simplify_action env tl) }
| Action_ite hd then_ else_ -> {a with v = Action_ite (simplify_expr env hd) (simplify_action env then_) (simplify_action_opt env else_) }
| Action_let i aa k -> {a with v = Action_let i (simplify_atomic_action env aa) (simplify_action env k) }
| Action_act a -> { a with v = Action_act (simplify_action env a) }
and simplify_action_opt (env:T.env_t) (a:option action) : ML (option action) =
match a with
| None -> None
| Some a -> Some (simplify_action env a) | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 42,
"end_line": 106,
"start_col": 0,
"start_line": 96
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata
*)
let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta}
let simplify_atomic_action (env:T.env_t) (a:atomic_action)
: ML atomic_action
= match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs ->
Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args) | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> a: Ast.action -> FStar.All.ML Ast.action | FStar.All.ML | [
"ml"
] | [
"simplify_action",
"simplify_action_opt"
] | [
"TypeSizes.env_t",
"Ast.action",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.action'",
"Ast.atomic_action",
"Ast.Mkwith_meta_t",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Ast.Atomic_action",
"Simplify.simplify_atomic_action",
"Ast.with_meta_t",
"Ast.Action_seq",
"Simplify.simplify_action",
"Ast.expr",
"FStar.Pervasives.Native.option",
"Ast.Action_ite",
"Simplify.simplify_action_opt",
"Simplify.simplify_expr",
"Ast.ident",
"Ast.Action_let",
"Ast.Action_act"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec simplify_action (env: T.env_t) (a: action) : ML action =
| match a.v with
| Atomic_action aa -> { a with v = Atomic_action (simplify_atomic_action env aa) }
| Action_seq hd tl ->
{ a with v = Action_seq (simplify_atomic_action env hd) (simplify_action env tl) }
| Action_ite hd then_ else_ ->
{
a with
v
=
Action_ite (simplify_expr env hd) (simplify_action env then_) (simplify_action_opt env else_)
}
| Action_let i aa k ->
{ a with v = Action_let i (simplify_atomic_action env aa) (simplify_action env k) }
| Action_act a -> { a with v = Action_act (simplify_action env a) } | false |
ZetaHashAccumulator.fst | ZetaHashAccumulator.hash_value_t | val hash_value_t : Type0 | let hash_value_t =
raw_hash_value_t &
ℕ | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 73,
"start_col": 0,
"start_line": 71
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32} | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"ZetaHashAccumulator.raw_hash_value_t",
"Prims.nat"
] | [] | false | false | false | true | true | let hash_value_t =
| raw_hash_value_t & nat | false |
|
ZetaHashAccumulator.fst | ZetaHashAccumulator.dummy_buf | val dummy_buf : Type0 | let dummy_buf = x:A.larray U8.t 1 { A.is_full_array x } | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 55,
"end_line": 214,
"start_col": 0,
"start_line": 214
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32}
// A hash value is a pair of a (cumulative) hash and a counter
let hash_value_t =
raw_hash_value_t &
ℕ
let initial_hash
: hash_value_t
= Seq.create 32 0uy, 0
// We just assume a spec for Blake, rather than connecting with the actual HACL code
assume
val blake_spec (d:Seq.seq U8.t { Seq.length d <= blake2_max_input_length})
: out:Seq.seq U8.t { Seq.length out == 32 }
// Hashing a single value just calls Blake and sets the counter to 1
let hash_one_value (s:Seq.seq U8.t { Seq.length s ≤ blake2_max_input_length })
: hash_value_t
= blake_spec s, 1
// Hash accumulation is by XOR
let xor_bytes (s1:bytes) (s2:bytes { Seq.length s1 == Seq.length s2 }) : bytes
= Seq.init (Seq.length s1)
(λ i → Seq.index s1 i `FStar.UInt8.logxor` Seq.index s2 i)
// A version (useful for induction) of xor_bytes that only XORs the first i bytes
// In Zeta, i is requires to be less than the length of the s1
// But, here, I "overdefine" the function, which makes it a bit easier to use
// in aggregate_raw_hashes.
// We should also try to make the version with the refinement on i work
let xor_bytes_pfx (s1:bytes)
(s2:bytes { Seq.length s1 == Seq.length s2 })
(i:ℕ)
: bytes
= let i = if i > Seq.length s1 then Seq.length s1 else i in
Seq.append
(xor_bytes (Seq.slice s1 0 i) (Seq.slice s2 0 i))
(Seq.slice s1 i (Seq.length s1))
// A lemma that says that if we XOR the first i bytes of two sequences, and then
// XOR the i-th byte, we get the same result as XORing the first (i+1) bytes
let extend_hash_value (s1 s2:bytes)
(i:ℕ)
: Lemma (requires Seq.length s1 == Seq.length s2 ∧
i < Seq.length s1)
(ensures Seq.upd (xor_bytes_pfx s1 s2 i)
i
(U8.logxor (Seq.index s1 i) (Seq.index s2 i))
`Seq.equal`
xor_bytes_pfx s1 s2 (i + 1))
= ()
// Aggregating two hashes is just XORing the two hashes and adding the counters
let aggregate_hashes (h0 h1: hash_value_t)
: hash_value_t
= xor_bytes (fst h0) (fst h1),
snd h0 + snd h1
(* END Pure Spec *)
(***************************************************************)
(* Model of HACL's blake2b *)
assume
val blake2b:
nn:SZ.t{1 ≤ SZ.v nn ∧ SZ.v nn ≤ 64}
-> output: A.array U8.t { A.length output == SZ.v nn}
-> ll: SZ.t { SZ.v ll <= blake2_max_input_length}
-> d:A.array U8.t { SZ.v ll ≤ A.length d}
-> kk: SZ.t { kk == 0sz } //We do not use blake2 in keyed mode
-> _dummy: A.array U8.t // this really should be a NULL, but krml doesn't extract Steel's null pointers yet
-> #sout:Ghost.erased (Seq.lseq U8.t 32)
-> #p:perm
-> #sd:Ghost.erased (Seq.seq U8.t) { Seq.length sd == SZ.v ll}
-> stt unit
(A.pts_to output sout ** A.pts_to d #p sd)
(λ _ → A.pts_to output (blake_spec (Seq.slice sd 0 (SZ.v ll)))
**
A.pts_to d #p sd)
(***************************************************************)
(* Pulse *)
// A buffer with the input to be hashed
let hashable_buffer = b:A.array U8.t { A.length b ≤ blake2_max_input_length }
// A buffer holding the raw hash value
let hash_value_buf = x:A.array U8.t { A.length x == 32 ∧ A.is_full_array x }
// The main data structure: ha_core
// This contains a buffer with the raw hash value
// and a mutable counter
noeq
type ha_core = {
acc: hash_value_buf;
ctr: ref U32.t;
}
// The representation predicate for ha_core ties it to a hash_value_t
// An interesting bit is that at the spec level, a hash_value_t's counter
// is just a nat. But, at the implementation level, it is a U32.t,
// and the code has to take care of potential overflow. So, at the spec
// level we connect the nat and the concrete counter, indicating that
// the counter hasn't overflowed yet.
let ha_val_core (core:ha_core) (h:hash_value_t)
: vprop
= A.pts_to core.acc (fst h) **
(exists* (n:U32.t).
pure (U32.v n == snd h) **
pts_to core.ctr n)
// Working with records and representation predicates involves a bit of boilerplate
// This ghost function packages up permission on the fields of a ha_core into
// ha_val_core using Pulse's primitive `fold` operation
```pulse
ghost
fn fold_ha_val_core (#acc:Seq.lseq U8.t 32) (h:ha_core)
requires
A.pts_to h.acc acc **
pts_to h.ctr n
ensures
ha_val_core h (acc, U32.v n)
{
fold (ha_val_core h (acc, U32.v n));
}
```
// This too is a bit of boilerplate. It use fold_ha_val_core, but also
// creates and returns a new ha_core value
```pulse
fn package_core (#vacc:erased (Seq.lseq U8.t 32)) (acc:hash_value_buf) (ctr:ref U32.t)
requires A.pts_to acc vacc **
pts_to ctr 'vctr
returns h:ha_core
ensures ha_val_core h (reveal vacc, U32.v 'vctr) **
pure (h == { acc; ctr } )
{
let core = { acc; ctr };
rewrite each acc as core.acc, ctr as core.ctr;
fold_ha_val_core core;
core
}
```
// A quirk of the Blake spec is that we need a dummy buffer to pass to it | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.Array.Core.larray",
"FStar.UInt8.t",
"Pulse.Lib.Array.Core.is_full_array"
] | [] | false | false | false | true | true | let dummy_buf =
| x: A.larray U8.t 1 {A.is_full_array x} | false |
|
ZetaHashAccumulator.fst | ZetaHashAccumulator.hashable_bytes | val hashable_bytes : Type0 | let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length } | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 71,
"end_line": 64,
"start_col": 0,
"start_line": 64
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"ZetaHashAccumulator.bytes",
"Prims.b2t",
"Pulse.Lib.BoundedIntegers.op_Less_Equals",
"Prims.int",
"Pulse.Lib.BoundedIntegers.bounded_int_int",
"FStar.Seq.Base.length",
"FStar.UInt8.t",
"ZetaHashAccumulator.blake2_max_input_length"
] | [] | false | false | false | true | true | let hashable_bytes =
| s: bytes{Seq.length s <= blake2_max_input_length} | false |
|
Simplify.fst | Simplify.simplify_field_array | val simplify_field_array (env: T.env_t) (f: field_array_t) : ML field_array_t | val simplify_field_array (env: T.env_t) (f: field_array_t) : ML field_array_t | let simplify_field_array (env:T.env_t) (f:field_array_t) : ML field_array_t =
match f with
| FieldScalar -> FieldScalar
| FieldArrayQualified (e, b) -> FieldArrayQualified (simplify_expr env e, b)
| FieldString sz -> FieldString (map_opt (simplify_expr env) sz)
| FieldConsumeAll -> FieldConsumeAll | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 38,
"end_line": 114,
"start_col": 0,
"start_line": 109
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata
*)
let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta}
let simplify_atomic_action (env:T.env_t) (a:atomic_action)
: ML atomic_action
= match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs ->
Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args)
| _ -> a //action mutable identifiers are not subject to substitution
let rec simplify_action (env:T.env_t) (a:action) : ML action =
match a.v with
| Atomic_action aa -> {a with v = Atomic_action (simplify_atomic_action env aa)}
| Action_seq hd tl -> {a with v = Action_seq (simplify_atomic_action env hd) (simplify_action env tl) }
| Action_ite hd then_ else_ -> {a with v = Action_ite (simplify_expr env hd) (simplify_action env then_) (simplify_action_opt env else_) }
| Action_let i aa k -> {a with v = Action_let i (simplify_atomic_action env aa) (simplify_action env k) }
| Action_act a -> { a with v = Action_act (simplify_action env a) }
and simplify_action_opt (env:T.env_t) (a:option action) : ML (option action) =
match a with
| None -> None
| Some a -> Some (simplify_action env a) | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> f: Ast.field_array_t -> FStar.All.ML Ast.field_array_t | FStar.All.ML | [
"ml"
] | [] | [
"TypeSizes.env_t",
"Ast.field_array_t",
"Ast.FieldScalar",
"Ast.expr",
"Ast.array_qualifier",
"Ast.FieldArrayQualified",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Simplify.simplify_expr",
"FStar.Pervasives.Native.option",
"Ast.FieldString",
"Ast.map_opt",
"Ast.FieldConsumeAll"
] | [] | false | true | false | false | false | let simplify_field_array (env: T.env_t) (f: field_array_t) : ML field_array_t =
| match f with
| FieldScalar -> FieldScalar
| FieldArrayQualified (e, b) -> FieldArrayQualified (simplify_expr env e, b)
| FieldString sz -> FieldString (map_opt (simplify_expr env) sz)
| FieldConsumeAll -> FieldConsumeAll | false |
Simplify.fst | Simplify.simplify_field | val simplify_field (env: T.env_t) (f: field) : ML field | val simplify_field (env: T.env_t) (f: field) : ML field | let rec simplify_field (env:T.env_t) (f:field)
: ML field
= match f.v with
| AtomicField af -> { f with v = AtomicField (simplify_atomic_field env af) }
| RecordField fs i -> { f with v = RecordField (List.map (simplify_field env) fs) i }
| SwitchCaseField swc i -> { f with v = SwitchCaseField (simplify_switch_case env swc) i }
and simplify_switch_case (env:T.env_t) (c:switch_case)
: ML switch_case =
let (e, cases) = c in
let e = simplify_expr env e in
let cases =
List.map
(function Case e f -> Case (simplify_expr env e) (simplify_field env f)
| DefaultCase f -> DefaultCase (simplify_field env f))
cases
in
e, cases | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 10,
"end_line": 150,
"start_col": 0,
"start_line": 133
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata
*)
let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta}
let simplify_atomic_action (env:T.env_t) (a:atomic_action)
: ML atomic_action
= match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs ->
Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args)
| _ -> a //action mutable identifiers are not subject to substitution
let rec simplify_action (env:T.env_t) (a:action) : ML action =
match a.v with
| Atomic_action aa -> {a with v = Atomic_action (simplify_atomic_action env aa)}
| Action_seq hd tl -> {a with v = Action_seq (simplify_atomic_action env hd) (simplify_action env tl) }
| Action_ite hd then_ else_ -> {a with v = Action_ite (simplify_expr env hd) (simplify_action env then_) (simplify_action_opt env else_) }
| Action_let i aa k -> {a with v = Action_let i (simplify_atomic_action env aa) (simplify_action env k) }
| Action_act a -> { a with v = Action_act (simplify_action env a) }
and simplify_action_opt (env:T.env_t) (a:option action) : ML (option action) =
match a with
| None -> None
| Some a -> Some (simplify_action env a)
let simplify_field_array (env:T.env_t) (f:field_array_t) : ML field_array_t =
match f with
| FieldScalar -> FieldScalar
| FieldArrayQualified (e, b) -> FieldArrayQualified (simplify_expr env e, b)
| FieldString sz -> FieldString (map_opt (simplify_expr env) sz)
| FieldConsumeAll -> FieldConsumeAll
let simplify_atomic_field (env:T.env_t) (f:atomic_field)
: ML atomic_field
= let sf = f.v in
let ft = simplify_typ env sf.field_type in
let fa = simplify_field_array env sf.field_array_opt in
let fc = sf.field_constraint |> map_opt (simplify_expr env) in
let fact =
match sf.field_action with
| None -> None
| Some (a, b) -> Some (simplify_action env a, b)
in
let sf = { sf with field_type = ft;
field_array_opt = fa;
field_constraint = fc;
field_action = fact } in
{ f with v = sf } | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> f: Ast.field -> FStar.All.ML Ast.field | FStar.All.ML | [
"ml"
] | [
"simplify_field",
"simplify_switch_case"
] | [
"TypeSizes.env_t",
"Ast.field",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.field'",
"Ast.with_meta_t",
"Ast.atomic_field'",
"Ast.Mkwith_meta_t",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Ast.AtomicField",
"Simplify.simplify_atomic_field",
"Ast.atomic_field",
"Prims.list",
"Ast.ident",
"Ast.RecordField",
"FStar.List.map",
"Simplify.simplify_field",
"FStar.Pervasives.Native.tuple2",
"Ast.expr",
"Ast.case",
"Ast.SwitchCaseField",
"Simplify.simplify_switch_case",
"Ast.switch_case"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec simplify_field (env: T.env_t) (f: field) : ML field =
| match f.v with
| AtomicField af -> { f with v = AtomicField (simplify_atomic_field env af) }
| RecordField fs i -> { f with v = RecordField (List.map (simplify_field env) fs) i }
| SwitchCaseField swc i -> { f with v = SwitchCaseField (simplify_switch_case env swc) i } | false |
Simplify.fst | Simplify.simplify_action_opt | val simplify_action_opt (env: T.env_t) (a: option action) : ML (option action) | val simplify_action_opt (env: T.env_t) (a: option action) : ML (option action) | let rec simplify_action (env:T.env_t) (a:action) : ML action =
match a.v with
| Atomic_action aa -> {a with v = Atomic_action (simplify_atomic_action env aa)}
| Action_seq hd tl -> {a with v = Action_seq (simplify_atomic_action env hd) (simplify_action env tl) }
| Action_ite hd then_ else_ -> {a with v = Action_ite (simplify_expr env hd) (simplify_action env then_) (simplify_action_opt env else_) }
| Action_let i aa k -> {a with v = Action_let i (simplify_atomic_action env aa) (simplify_action env k) }
| Action_act a -> { a with v = Action_act (simplify_action env a) }
and simplify_action_opt (env:T.env_t) (a:option action) : ML (option action) =
match a with
| None -> None
| Some a -> Some (simplify_action env a) | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 42,
"end_line": 106,
"start_col": 0,
"start_line": 96
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata
*)
let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta}
let simplify_atomic_action (env:T.env_t) (a:atomic_action)
: ML atomic_action
= match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs ->
Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args) | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> a: FStar.Pervasives.Native.option Ast.action
-> FStar.All.ML (FStar.Pervasives.Native.option Ast.action) | FStar.All.ML | [
"ml"
] | [
"simplify_action",
"simplify_action_opt"
] | [
"TypeSizes.env_t",
"FStar.Pervasives.Native.option",
"Ast.action",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"Simplify.simplify_action"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec simplify_action_opt (env: T.env_t) (a: option action) : ML (option action) =
| match a with
| None -> None
| Some a -> Some (simplify_action env a) | false |
Simplify.fst | Simplify.simplify_typ_param | val simplify_typ_param (env: T.env_t) (p: typ_param) : ML typ_param | val simplify_typ_param (env: T.env_t) (p: typ_param) : ML typ_param | let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta} | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 63,
"end_line": 84,
"start_col": 0,
"start_line": 51
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> p: Ast.typ_param -> FStar.All.ML Ast.typ_param | FStar.All.ML | [
"ml"
] | [
"simplify_typ_param",
"simplify_typ",
"simplify_out_expr_node",
"simplify_out_expr_meta",
"simplify_out_expr"
] | [
"TypeSizes.env_t",
"Ast.typ_param",
"Ast.expr",
"Ast.Inl",
"Ast.out_expr",
"Simplify.simplify_expr",
"Ast.Inr",
"Simplify.simplify_out_expr"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec simplify_typ_param (env: T.env_t) (p: typ_param) : ML typ_param =
| match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr | false |
ZetaHashAccumulator.fst | ZetaHashAccumulator.hash_value_buf | val hash_value_buf : Type0 | let hash_value_buf = x:A.array U8.t { A.length x == 32 ∧ A.is_full_array x } | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 77,
"end_line": 155,
"start_col": 0,
"start_line": 155
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32}
// A hash value is a pair of a (cumulative) hash and a counter
let hash_value_t =
raw_hash_value_t &
ℕ
let initial_hash
: hash_value_t
= Seq.create 32 0uy, 0
// We just assume a spec for Blake, rather than connecting with the actual HACL code
assume
val blake_spec (d:Seq.seq U8.t { Seq.length d <= blake2_max_input_length})
: out:Seq.seq U8.t { Seq.length out == 32 }
// Hashing a single value just calls Blake and sets the counter to 1
let hash_one_value (s:Seq.seq U8.t { Seq.length s ≤ blake2_max_input_length })
: hash_value_t
= blake_spec s, 1
// Hash accumulation is by XOR
let xor_bytes (s1:bytes) (s2:bytes { Seq.length s1 == Seq.length s2 }) : bytes
= Seq.init (Seq.length s1)
(λ i → Seq.index s1 i `FStar.UInt8.logxor` Seq.index s2 i)
// A version (useful for induction) of xor_bytes that only XORs the first i bytes
// In Zeta, i is requires to be less than the length of the s1
// But, here, I "overdefine" the function, which makes it a bit easier to use
// in aggregate_raw_hashes.
// We should also try to make the version with the refinement on i work
let xor_bytes_pfx (s1:bytes)
(s2:bytes { Seq.length s1 == Seq.length s2 })
(i:ℕ)
: bytes
= let i = if i > Seq.length s1 then Seq.length s1 else i in
Seq.append
(xor_bytes (Seq.slice s1 0 i) (Seq.slice s2 0 i))
(Seq.slice s1 i (Seq.length s1))
// A lemma that says that if we XOR the first i bytes of two sequences, and then
// XOR the i-th byte, we get the same result as XORing the first (i+1) bytes
let extend_hash_value (s1 s2:bytes)
(i:ℕ)
: Lemma (requires Seq.length s1 == Seq.length s2 ∧
i < Seq.length s1)
(ensures Seq.upd (xor_bytes_pfx s1 s2 i)
i
(U8.logxor (Seq.index s1 i) (Seq.index s2 i))
`Seq.equal`
xor_bytes_pfx s1 s2 (i + 1))
= ()
// Aggregating two hashes is just XORing the two hashes and adding the counters
let aggregate_hashes (h0 h1: hash_value_t)
: hash_value_t
= xor_bytes (fst h0) (fst h1),
snd h0 + snd h1
(* END Pure Spec *)
(***************************************************************)
(* Model of HACL's blake2b *)
assume
val blake2b:
nn:SZ.t{1 ≤ SZ.v nn ∧ SZ.v nn ≤ 64}
-> output: A.array U8.t { A.length output == SZ.v nn}
-> ll: SZ.t { SZ.v ll <= blake2_max_input_length}
-> d:A.array U8.t { SZ.v ll ≤ A.length d}
-> kk: SZ.t { kk == 0sz } //We do not use blake2 in keyed mode
-> _dummy: A.array U8.t // this really should be a NULL, but krml doesn't extract Steel's null pointers yet
-> #sout:Ghost.erased (Seq.lseq U8.t 32)
-> #p:perm
-> #sd:Ghost.erased (Seq.seq U8.t) { Seq.length sd == SZ.v ll}
-> stt unit
(A.pts_to output sout ** A.pts_to d #p sd)
(λ _ → A.pts_to output (blake_spec (Seq.slice sd 0 (SZ.v ll)))
**
A.pts_to d #p sd)
(***************************************************************)
(* Pulse *)
// A buffer with the input to be hashed
let hashable_buffer = b:A.array U8.t { A.length b ≤ blake2_max_input_length } | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.Array.Core.array",
"FStar.UInt8.t",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Pulse.Lib.Array.Core.length",
"Pulse.Lib.Array.Core.is_full_array"
] | [] | false | false | false | true | true | let hash_value_buf =
| x: A.array U8.t {A.length x == 32 /\ A.is_full_array x} | false |
|
Simplify.fst | Simplify.simplify_out_expr_meta | val simplify_out_expr_meta (env: T.env_t) (mopt: option out_expr_meta_t)
: ML (option out_expr_meta_t) | val simplify_out_expr_meta (env: T.env_t) (mopt: option out_expr_meta_t)
: ML (option out_expr_meta_t) | let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta} | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 63,
"end_line": 84,
"start_col": 0,
"start_line": 51
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> mopt: FStar.Pervasives.Native.option Ast.out_expr_meta_t
-> FStar.All.ML (FStar.Pervasives.Native.option Ast.out_expr_meta_t) | FStar.All.ML | [
"ml"
] | [
"simplify_typ_param",
"simplify_typ",
"simplify_out_expr_node",
"simplify_out_expr_meta",
"simplify_out_expr"
] | [
"TypeSizes.env_t",
"FStar.Pervasives.Native.option",
"Ast.out_expr_meta_t",
"FStar.Pervasives.Native.None",
"Ast.with_meta_t",
"Ast.typ'",
"Prims.int",
"FStar.Pervasives.Native.Some",
"Ast.Mkout_expr_meta_t",
"Simplify.simplify_typ",
"Ast.typ"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec simplify_out_expr_meta (env: T.env_t) (mopt: option out_expr_meta_t)
: ML (option out_expr_meta_t) =
| match mopt with
| None -> None
| Some { out_expr_base_t = bt ; out_expr_t = t ; out_expr_bit_width = n } ->
Some
({
out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n
}) | false |
Simplify.fst | Simplify.simplify_out_expr_node | val simplify_out_expr_node (env: T.env_t) (oe: with_meta_t out_expr') : ML (with_meta_t out_expr') | val simplify_out_expr_node (env: T.env_t) (oe: with_meta_t out_expr') : ML (with_meta_t out_expr') | let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta} | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 63,
"end_line": 84,
"start_col": 0,
"start_line": 51
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> oe: Ast.with_meta_t Ast.out_expr'
-> FStar.All.ML (Ast.with_meta_t Ast.out_expr') | FStar.All.ML | [
"ml"
] | [
"simplify_typ_param",
"simplify_typ",
"simplify_out_expr_node",
"simplify_out_expr_meta",
"simplify_out_expr"
] | [
"TypeSizes.env_t",
"Ast.with_meta_t",
"Ast.out_expr'"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec simplify_out_expr_node (env: T.env_t) (oe: with_meta_t out_expr')
: ML (with_meta_t out_expr') =
| oe | false |
ZetaHashAccumulator.fst | ZetaHashAccumulator.ha_val | val ha_val : h: ZetaHashAccumulator.ha -> s: ZetaHashAccumulator.hash_value_t -> Pulse.Lib.Core.vprop | let ha_val (h:ha) (s:hash_value_t) =
ha_val_core h.core s **
(exists* (s:Seq.lseq U8.t 32). A.pts_to h.tmp s) **
A.pts_to h.dummy (Seq.create 1 0uy) | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 231,
"start_col": 0,
"start_line": 228
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32}
// A hash value is a pair of a (cumulative) hash and a counter
let hash_value_t =
raw_hash_value_t &
ℕ
let initial_hash
: hash_value_t
= Seq.create 32 0uy, 0
// We just assume a spec for Blake, rather than connecting with the actual HACL code
assume
val blake_spec (d:Seq.seq U8.t { Seq.length d <= blake2_max_input_length})
: out:Seq.seq U8.t { Seq.length out == 32 }
// Hashing a single value just calls Blake and sets the counter to 1
let hash_one_value (s:Seq.seq U8.t { Seq.length s ≤ blake2_max_input_length })
: hash_value_t
= blake_spec s, 1
// Hash accumulation is by XOR
let xor_bytes (s1:bytes) (s2:bytes { Seq.length s1 == Seq.length s2 }) : bytes
= Seq.init (Seq.length s1)
(λ i → Seq.index s1 i `FStar.UInt8.logxor` Seq.index s2 i)
// A version (useful for induction) of xor_bytes that only XORs the first i bytes
// In Zeta, i is requires to be less than the length of the s1
// But, here, I "overdefine" the function, which makes it a bit easier to use
// in aggregate_raw_hashes.
// We should also try to make the version with the refinement on i work
let xor_bytes_pfx (s1:bytes)
(s2:bytes { Seq.length s1 == Seq.length s2 })
(i:ℕ)
: bytes
= let i = if i > Seq.length s1 then Seq.length s1 else i in
Seq.append
(xor_bytes (Seq.slice s1 0 i) (Seq.slice s2 0 i))
(Seq.slice s1 i (Seq.length s1))
// A lemma that says that if we XOR the first i bytes of two sequences, and then
// XOR the i-th byte, we get the same result as XORing the first (i+1) bytes
let extend_hash_value (s1 s2:bytes)
(i:ℕ)
: Lemma (requires Seq.length s1 == Seq.length s2 ∧
i < Seq.length s1)
(ensures Seq.upd (xor_bytes_pfx s1 s2 i)
i
(U8.logxor (Seq.index s1 i) (Seq.index s2 i))
`Seq.equal`
xor_bytes_pfx s1 s2 (i + 1))
= ()
// Aggregating two hashes is just XORing the two hashes and adding the counters
let aggregate_hashes (h0 h1: hash_value_t)
: hash_value_t
= xor_bytes (fst h0) (fst h1),
snd h0 + snd h1
(* END Pure Spec *)
(***************************************************************)
(* Model of HACL's blake2b *)
assume
val blake2b:
nn:SZ.t{1 ≤ SZ.v nn ∧ SZ.v nn ≤ 64}
-> output: A.array U8.t { A.length output == SZ.v nn}
-> ll: SZ.t { SZ.v ll <= blake2_max_input_length}
-> d:A.array U8.t { SZ.v ll ≤ A.length d}
-> kk: SZ.t { kk == 0sz } //We do not use blake2 in keyed mode
-> _dummy: A.array U8.t // this really should be a NULL, but krml doesn't extract Steel's null pointers yet
-> #sout:Ghost.erased (Seq.lseq U8.t 32)
-> #p:perm
-> #sd:Ghost.erased (Seq.seq U8.t) { Seq.length sd == SZ.v ll}
-> stt unit
(A.pts_to output sout ** A.pts_to d #p sd)
(λ _ → A.pts_to output (blake_spec (Seq.slice sd 0 (SZ.v ll)))
**
A.pts_to d #p sd)
(***************************************************************)
(* Pulse *)
// A buffer with the input to be hashed
let hashable_buffer = b:A.array U8.t { A.length b ≤ blake2_max_input_length }
// A buffer holding the raw hash value
let hash_value_buf = x:A.array U8.t { A.length x == 32 ∧ A.is_full_array x }
// The main data structure: ha_core
// This contains a buffer with the raw hash value
// and a mutable counter
noeq
type ha_core = {
acc: hash_value_buf;
ctr: ref U32.t;
}
// The representation predicate for ha_core ties it to a hash_value_t
// An interesting bit is that at the spec level, a hash_value_t's counter
// is just a nat. But, at the implementation level, it is a U32.t,
// and the code has to take care of potential overflow. So, at the spec
// level we connect the nat and the concrete counter, indicating that
// the counter hasn't overflowed yet.
let ha_val_core (core:ha_core) (h:hash_value_t)
: vprop
= A.pts_to core.acc (fst h) **
(exists* (n:U32.t).
pure (U32.v n == snd h) **
pts_to core.ctr n)
// Working with records and representation predicates involves a bit of boilerplate
// This ghost function packages up permission on the fields of a ha_core into
// ha_val_core using Pulse's primitive `fold` operation
```pulse
ghost
fn fold_ha_val_core (#acc:Seq.lseq U8.t 32) (h:ha_core)
requires
A.pts_to h.acc acc **
pts_to h.ctr n
ensures
ha_val_core h (acc, U32.v n)
{
fold (ha_val_core h (acc, U32.v n));
}
```
// This too is a bit of boilerplate. It use fold_ha_val_core, but also
// creates and returns a new ha_core value
```pulse
fn package_core (#vacc:erased (Seq.lseq U8.t 32)) (acc:hash_value_buf) (ctr:ref U32.t)
requires A.pts_to acc vacc **
pts_to ctr 'vctr
returns h:ha_core
ensures ha_val_core h (reveal vacc, U32.v 'vctr) **
pure (h == { acc; ctr } )
{
let core = { acc; ctr };
rewrite each acc as core.acc, ctr as core.ctr;
fold_ha_val_core core;
core
}
```
// A quirk of the Blake spec is that we need a dummy buffer to pass to it
// which could contain a key, but we're not using it in keyed mode
let dummy_buf = x:A.larray U8.t 1 { A.is_full_array x }
// The full structure holds a core hash value, but also a temporary buffer
// into which to hash new values, and the dummy buffer
noeq
type ha = {
core: ha_core;
tmp: hash_value_buf;
dummy: dummy_buf
}
// Again, we play the same game as with ha_core | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: ZetaHashAccumulator.ha -> s: ZetaHashAccumulator.hash_value_t -> Pulse.Lib.Core.vprop | Prims.Tot | [
"total"
] | [] | [
"ZetaHashAccumulator.ha",
"ZetaHashAccumulator.hash_value_t",
"Pulse.Lib.Core.op_Star_Star",
"ZetaHashAccumulator.ha_val_core",
"ZetaHashAccumulator.__proj__Mkha__item__core",
"Pulse.Lib.Core.op_exists_Star",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Pulse.Lib.Array.Core.pts_to",
"ZetaHashAccumulator.__proj__Mkha__item__tmp",
"PulseCore.FractionalPermission.full_perm",
"Pulse.Lib.Core.vprop",
"ZetaHashAccumulator.__proj__Mkha__item__dummy",
"FStar.Seq.Base.create",
"FStar.UInt8.__uint_to_t"
] | [] | false | false | false | true | false | let ha_val (h: ha) (s: hash_value_t) =
| (ha_val_core h.core s ** (exists* (s: Seq.lseq U8.t 32). A.pts_to h.tmp s)) **
A.pts_to h.dummy (Seq.create 1 0uy) | false |
|
Simplify.fst | Simplify.simplify_out_expr | val simplify_out_expr (env: T.env_t) (oe: out_expr) : ML out_expr | val simplify_out_expr (env: T.env_t) (oe: out_expr) : ML out_expr | let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta} | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 63,
"end_line": 84,
"start_col": 0,
"start_line": 51
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> oe: Ast.out_expr -> FStar.All.ML Ast.out_expr | FStar.All.ML | [
"ml"
] | [
"simplify_typ_param",
"simplify_typ",
"simplify_out_expr_node",
"simplify_out_expr_meta",
"simplify_out_expr"
] | [
"TypeSizes.env_t",
"Ast.out_expr",
"Ast.Mkout_expr",
"FStar.Pervasives.Native.option",
"Ast.out_expr_meta_t",
"Simplify.simplify_out_expr_meta",
"Ast.__proj__Mkout_expr__item__out_expr_meta",
"Ast.with_meta_t",
"Ast.out_expr'",
"Simplify.simplify_out_expr_node",
"Ast.__proj__Mkout_expr__item__out_expr_node"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec simplify_out_expr (env: T.env_t) (oe: out_expr) : ML out_expr =
| {
oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta
} | false |
Simplify.fst | Simplify.simplify_out_fields | val simplify_out_fields (env: T.env_t) (flds: list out_field) : ML (list out_field) | val simplify_out_fields (env: T.env_t) (flds: list out_field) : ML (list out_field) | let rec simplify_out_fields (env:T.env_t) (flds:list out_field) : ML (list out_field) =
List.map (fun fld -> match fld with
| Out_field_named id t n -> Out_field_named id (simplify_typ env t) n
| Out_field_anon flds is_union ->
Out_field_anon (simplify_out_fields env flds) is_union) flds | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 66,
"end_line": 157,
"start_col": 0,
"start_line": 153
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata
*)
let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta}
let simplify_atomic_action (env:T.env_t) (a:atomic_action)
: ML atomic_action
= match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs ->
Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args)
| _ -> a //action mutable identifiers are not subject to substitution
let rec simplify_action (env:T.env_t) (a:action) : ML action =
match a.v with
| Atomic_action aa -> {a with v = Atomic_action (simplify_atomic_action env aa)}
| Action_seq hd tl -> {a with v = Action_seq (simplify_atomic_action env hd) (simplify_action env tl) }
| Action_ite hd then_ else_ -> {a with v = Action_ite (simplify_expr env hd) (simplify_action env then_) (simplify_action_opt env else_) }
| Action_let i aa k -> {a with v = Action_let i (simplify_atomic_action env aa) (simplify_action env k) }
| Action_act a -> { a with v = Action_act (simplify_action env a) }
and simplify_action_opt (env:T.env_t) (a:option action) : ML (option action) =
match a with
| None -> None
| Some a -> Some (simplify_action env a)
let simplify_field_array (env:T.env_t) (f:field_array_t) : ML field_array_t =
match f with
| FieldScalar -> FieldScalar
| FieldArrayQualified (e, b) -> FieldArrayQualified (simplify_expr env e, b)
| FieldString sz -> FieldString (map_opt (simplify_expr env) sz)
| FieldConsumeAll -> FieldConsumeAll
let simplify_atomic_field (env:T.env_t) (f:atomic_field)
: ML atomic_field
= let sf = f.v in
let ft = simplify_typ env sf.field_type in
let fa = simplify_field_array env sf.field_array_opt in
let fc = sf.field_constraint |> map_opt (simplify_expr env) in
let fact =
match sf.field_action with
| None -> None
| Some (a, b) -> Some (simplify_action env a, b)
in
let sf = { sf with field_type = ft;
field_array_opt = fa;
field_constraint = fc;
field_action = fact } in
{ f with v = sf }
let rec simplify_field (env:T.env_t) (f:field)
: ML field
= match f.v with
| AtomicField af -> { f with v = AtomicField (simplify_atomic_field env af) }
| RecordField fs i -> { f with v = RecordField (List.map (simplify_field env) fs) i }
| SwitchCaseField swc i -> { f with v = SwitchCaseField (simplify_switch_case env swc) i }
and simplify_switch_case (env:T.env_t) (c:switch_case)
: ML switch_case =
let (e, cases) = c in
let e = simplify_expr env e in
let cases =
List.map
(function Case e f -> Case (simplify_expr env e) (simplify_field env f)
| DefaultCase f -> DefaultCase (simplify_field env f))
cases
in
e, cases | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> flds: Prims.list Ast.out_field -> FStar.All.ML (Prims.list Ast.out_field) | FStar.All.ML | [
"ml"
] | [] | [
"TypeSizes.env_t",
"Prims.list",
"Ast.out_field",
"FStar.List.map",
"Ast.ident",
"Ast.typ",
"FStar.Pervasives.Native.option",
"Prims.int",
"Ast.Out_field_named",
"Simplify.simplify_typ",
"Prims.bool",
"Ast.Out_field_anon",
"Simplify.simplify_out_fields"
] | [
"recursion"
] | false | true | false | false | false | let rec simplify_out_fields (env: T.env_t) (flds: list out_field) : ML (list out_field) =
| List.map (function
| Out_field_named id t n -> Out_field_named id (simplify_typ env t) n
| Out_field_anon flds is_union -> Out_field_anon (simplify_out_fields env flds) is_union)
flds | false |
Simplify.fst | Simplify.simplify_switch_case | val simplify_switch_case (env: T.env_t) (c: switch_case) : ML switch_case | val simplify_switch_case (env: T.env_t) (c: switch_case) : ML switch_case | let rec simplify_field (env:T.env_t) (f:field)
: ML field
= match f.v with
| AtomicField af -> { f with v = AtomicField (simplify_atomic_field env af) }
| RecordField fs i -> { f with v = RecordField (List.map (simplify_field env) fs) i }
| SwitchCaseField swc i -> { f with v = SwitchCaseField (simplify_switch_case env swc) i }
and simplify_switch_case (env:T.env_t) (c:switch_case)
: ML switch_case =
let (e, cases) = c in
let e = simplify_expr env e in
let cases =
List.map
(function Case e f -> Case (simplify_expr env e) (simplify_field env f)
| DefaultCase f -> DefaultCase (simplify_field env f))
cases
in
e, cases | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 10,
"end_line": 150,
"start_col": 0,
"start_line": 133
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata
*)
let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta}
let simplify_atomic_action (env:T.env_t) (a:atomic_action)
: ML atomic_action
= match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs ->
Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args)
| _ -> a //action mutable identifiers are not subject to substitution
let rec simplify_action (env:T.env_t) (a:action) : ML action =
match a.v with
| Atomic_action aa -> {a with v = Atomic_action (simplify_atomic_action env aa)}
| Action_seq hd tl -> {a with v = Action_seq (simplify_atomic_action env hd) (simplify_action env tl) }
| Action_ite hd then_ else_ -> {a with v = Action_ite (simplify_expr env hd) (simplify_action env then_) (simplify_action_opt env else_) }
| Action_let i aa k -> {a with v = Action_let i (simplify_atomic_action env aa) (simplify_action env k) }
| Action_act a -> { a with v = Action_act (simplify_action env a) }
and simplify_action_opt (env:T.env_t) (a:option action) : ML (option action) =
match a with
| None -> None
| Some a -> Some (simplify_action env a)
let simplify_field_array (env:T.env_t) (f:field_array_t) : ML field_array_t =
match f with
| FieldScalar -> FieldScalar
| FieldArrayQualified (e, b) -> FieldArrayQualified (simplify_expr env e, b)
| FieldString sz -> FieldString (map_opt (simplify_expr env) sz)
| FieldConsumeAll -> FieldConsumeAll
let simplify_atomic_field (env:T.env_t) (f:atomic_field)
: ML atomic_field
= let sf = f.v in
let ft = simplify_typ env sf.field_type in
let fa = simplify_field_array env sf.field_array_opt in
let fc = sf.field_constraint |> map_opt (simplify_expr env) in
let fact =
match sf.field_action with
| None -> None
| Some (a, b) -> Some (simplify_action env a, b)
in
let sf = { sf with field_type = ft;
field_array_opt = fa;
field_constraint = fc;
field_action = fact } in
{ f with v = sf } | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> c: Ast.switch_case -> FStar.All.ML Ast.switch_case | FStar.All.ML | [
"ml"
] | [
"simplify_field",
"simplify_switch_case"
] | [
"TypeSizes.env_t",
"Ast.switch_case",
"Ast.expr",
"Prims.list",
"Ast.case",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.map",
"Ast.with_meta_t",
"Ast.field'",
"Ast.Case",
"Simplify.simplify_field",
"Ast.field",
"Simplify.simplify_expr",
"Ast.DefaultCase"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec simplify_switch_case (env: T.env_t) (c: switch_case) : ML switch_case =
| let e, cases = c in
let e = simplify_expr env e in
let cases =
List.map (function
| Case e f -> Case (simplify_expr env e) (simplify_field env f)
| DefaultCase f -> DefaultCase (simplify_field env f))
cases
in
e, cases | false |
Simplify.fst | Simplify.simplify_typ | val simplify_typ (env: T.env_t) (t: typ) : ML typ | val simplify_typ (env: T.env_t) (t: typ) : ML typ | let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta} | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 63,
"end_line": 84,
"start_col": 0,
"start_line": 51
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> t: Ast.typ -> FStar.All.ML Ast.typ | FStar.All.ML | [
"ml"
] | [
"simplify_typ_param",
"simplify_typ",
"simplify_out_expr_node",
"simplify_out_expr_meta",
"simplify_out_expr"
] | [
"TypeSizes.env_t",
"Ast.typ",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.typ'",
"Ast.with_meta_t",
"Ast.Mkwith_meta_t",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Ast.Pointer",
"Simplify.simplify_typ",
"Ast.ident",
"Ast.t_kind",
"Prims.list",
"Ast.either",
"Ast.expr",
"Ast.out_expr",
"Binding.unfold_typ_abbrev_only",
"FStar.Pervasives.Native.fst",
"Binding.env",
"TypeSizes.size_env",
"Ast.Type_app",
"Binding.resolve_record_case_output_extern_type_name",
"FStar.List.map",
"Simplify.simplify_typ_param"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec simplify_typ (env: T.env_t) (t: typ) : ML typ =
| match t.v with
| Pointer t -> { t with v = Pointer (simplify_typ env t) }
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t | false |
Simplify.fst | Simplify.simplify_decl | val simplify_decl (env: T.env_t) (d: decl) : ML decl | val simplify_decl (env: T.env_t) (d: decl) : ML decl | let simplify_decl (env:T.env_t) (d:decl) : ML decl =
match d.d_decl.v with
| ModuleAbbrev _ _ -> d
| Define i None c -> d
| Define i (Some t) c -> decl_with_v d (Define i (Some (simplify_typ env t)) c)
| TypeAbbrev t i ->
let t' = simplify_typ env t in
B.update_typ_abbrev (fst env) i t';
decl_with_v d (TypeAbbrev t' i)
| Enum t i cases ->
let t = simplify_typ env t in
decl_with_v d (Enum t i cases)
| Record tdnames params wopt fields ->
let params = List.map (fun (t, i, q) -> simplify_typ env t, i, q) params in
let fields = List.map (simplify_field env) fields in
let wopt = match wopt with | None -> None | Some w -> Some (simplify_expr env w) in
decl_with_v d (Record tdnames params wopt fields)
| CaseType tdnames params switch ->
let params = List.map (fun (t, i, q) -> simplify_typ env t, i, q) params in
let switch = simplify_switch_case env switch in
decl_with_v d (CaseType tdnames params switch)
| OutputType out_t ->
decl_with_v d (OutputType ({out_t with out_typ_fields=simplify_out_fields env out_t.out_typ_fields}))
| ExternType tdnames -> d
| ExternFn f ret params ->
let ret = simplify_typ env ret in
let params = List.map (fun (t, i, q) -> simplify_typ env t, i, q) params in
decl_with_v d (ExternFn f ret params)
| ExternProbe _ -> d | {
"file_name": "src/3d/Simplify.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 22,
"end_line": 195,
"start_col": 0,
"start_line": 159
} | (*
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.
*)
module Simplify
open Ast
open FStar.All
module B = Binding
module T = TypeSizes
(*
This module implements a pass over the source AST
1. Simplifying refinement expressions, in particular reducing
sizeof expressions to constants
2. Reducing typedef abbreviations
*)
let rec simplify_expr (env:T.env_t) (e:expr)
: ML expr
= match e.v with
| This -> failwith "Impossible: should have been eliminated already"
| App SizeOf _ ->
begin
match T.value_of_const_expr env e with
| Some (Inr (t, n)) -> with_range (Constant (Int t n)) e.range
| _ -> error (Printf.sprintf "Could not evaluate %s to a compile-time constant" (print_expr e)) e.range
end
| App op es ->
let es = List.map (simplify_expr env) es in
{ e with v = App op es }
| _ -> e
(*
* Simplify output expressions, mainly their metadata to resolve
* abbrevs in the types that appear in the metadata
*)
let rec simplify_typ_param (env:T.env_t) (p:typ_param) : ML typ_param =
match p with
| Inl e -> simplify_expr env e |> Inl
| Inr oe -> simplify_out_expr env oe |> Inr
and simplify_typ (env:T.env_t) (t:typ)
: ML typ
= match t.v with
| Pointer t -> {t with v=Pointer (simplify_typ env t)}
| Type_app s b ps ->
let ps = List.map (simplify_typ_param env) ps in
let s = B.resolve_record_case_output_extern_type_name (fst env) s in
let t = { t with v = Type_app s b ps } in
B.unfold_typ_abbrev_only (fst env) t
and simplify_out_expr_node (env:T.env_t) (oe:with_meta_t out_expr')
: ML (with_meta_t out_expr')
= oe
and simplify_out_expr_meta (env:T.env_t) (mopt:option out_expr_meta_t)
: ML (option out_expr_meta_t)
= match mopt with
| None -> None
| Some ({ out_expr_base_t = bt;
out_expr_t = t;
out_expr_bit_width = n }) ->
Some ({ out_expr_base_t = simplify_typ env bt;
out_expr_t = simplify_typ env t;
out_expr_bit_width = n })
and simplify_out_expr (env:T.env_t) (oe:out_expr) : ML out_expr =
{oe with
out_expr_node = simplify_out_expr_node env oe.out_expr_node;
out_expr_meta = simplify_out_expr_meta env oe.out_expr_meta}
let simplify_atomic_action (env:T.env_t) (a:atomic_action)
: ML atomic_action
= match a with
| Action_return e -> Action_return (simplify_expr env e)
| Action_assignment lhs rhs ->
Action_assignment (simplify_out_expr env lhs) (simplify_expr env rhs)
| Action_field_ptr_after sz write_to ->
Action_field_ptr_after (simplify_expr env sz) (simplify_out_expr env write_to)
| Action_call f args -> Action_call f (List.map (simplify_expr env) args)
| _ -> a //action mutable identifiers are not subject to substitution
let rec simplify_action (env:T.env_t) (a:action) : ML action =
match a.v with
| Atomic_action aa -> {a with v = Atomic_action (simplify_atomic_action env aa)}
| Action_seq hd tl -> {a with v = Action_seq (simplify_atomic_action env hd) (simplify_action env tl) }
| Action_ite hd then_ else_ -> {a with v = Action_ite (simplify_expr env hd) (simplify_action env then_) (simplify_action_opt env else_) }
| Action_let i aa k -> {a with v = Action_let i (simplify_atomic_action env aa) (simplify_action env k) }
| Action_act a -> { a with v = Action_act (simplify_action env a) }
and simplify_action_opt (env:T.env_t) (a:option action) : ML (option action) =
match a with
| None -> None
| Some a -> Some (simplify_action env a)
let simplify_field_array (env:T.env_t) (f:field_array_t) : ML field_array_t =
match f with
| FieldScalar -> FieldScalar
| FieldArrayQualified (e, b) -> FieldArrayQualified (simplify_expr env e, b)
| FieldString sz -> FieldString (map_opt (simplify_expr env) sz)
| FieldConsumeAll -> FieldConsumeAll
let simplify_atomic_field (env:T.env_t) (f:atomic_field)
: ML atomic_field
= let sf = f.v in
let ft = simplify_typ env sf.field_type in
let fa = simplify_field_array env sf.field_array_opt in
let fc = sf.field_constraint |> map_opt (simplify_expr env) in
let fact =
match sf.field_action with
| None -> None
| Some (a, b) -> Some (simplify_action env a, b)
in
let sf = { sf with field_type = ft;
field_array_opt = fa;
field_constraint = fc;
field_action = fact } in
{ f with v = sf }
let rec simplify_field (env:T.env_t) (f:field)
: ML field
= match f.v with
| AtomicField af -> { f with v = AtomicField (simplify_atomic_field env af) }
| RecordField fs i -> { f with v = RecordField (List.map (simplify_field env) fs) i }
| SwitchCaseField swc i -> { f with v = SwitchCaseField (simplify_switch_case env swc) i }
and simplify_switch_case (env:T.env_t) (c:switch_case)
: ML switch_case =
let (e, cases) = c in
let e = simplify_expr env e in
let cases =
List.map
(function Case e f -> Case (simplify_expr env e) (simplify_field env f)
| DefaultCase f -> DefaultCase (simplify_field env f))
cases
in
e, cases
let rec simplify_out_fields (env:T.env_t) (flds:list out_field) : ML (list out_field) =
List.map (fun fld -> match fld with
| Out_field_named id t n -> Out_field_named id (simplify_typ env t) n
| Out_field_anon flds is_union ->
Out_field_anon (simplify_out_fields env flds) is_union) flds | {
"checked_file": "/",
"dependencies": [
"TypeSizes.fsti.checked",
"prims.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Binding.fsti.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "Simplify.fst"
} | [
{
"abbrev": true,
"full_module": "TypeSizes",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": true,
"full_module": "Binding",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: TypeSizes.env_t -> d: Ast.decl -> FStar.All.ML Ast.decl | FStar.All.ML | [
"ml"
] | [] | [
"TypeSizes.env_t",
"Ast.decl",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.decl'",
"Ast.__proj__Mkdecl__item__d_decl",
"Ast.ident",
"Ast.constant",
"Ast.typ",
"Ast.decl_with_v",
"Ast.Define",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Some",
"Simplify.simplify_typ",
"Ast.TypeAbbrev",
"Prims.unit",
"Binding.update_typ_abbrev",
"FStar.Pervasives.Native.fst",
"Binding.env",
"TypeSizes.size_env",
"Prims.list",
"Ast.enum_case",
"Ast.Enum",
"Ast.typedef_names",
"Ast.param",
"Ast.expr",
"Ast.record",
"Ast.Record",
"FStar.Pervasives.Native.None",
"Simplify.simplify_expr",
"Ast.with_meta_t",
"Ast.field'",
"FStar.List.map",
"Simplify.simplify_field",
"FStar.Pervasives.Native.tuple3",
"Ast.qualifier",
"FStar.Pervasives.Native.Mktuple3",
"Ast.switch_case",
"Ast.CaseType",
"Simplify.simplify_switch_case",
"Ast.out_typ",
"Ast.OutputType",
"Ast.Mkout_typ",
"Ast.__proj__Mkout_typ__item__out_typ_names",
"Ast.__proj__Mkout_typ__item__out_typ_is_union",
"Ast.out_field",
"Simplify.simplify_out_fields",
"Ast.__proj__Mkout_typ__item__out_typ_fields",
"Ast.ExternFn"
] | [] | false | true | false | false | false | let simplify_decl (env: T.env_t) (d: decl) : ML decl =
| match d.d_decl.v with
| ModuleAbbrev _ _ -> d
| Define i None c -> d
| Define i (Some t) c -> decl_with_v d (Define i (Some (simplify_typ env t)) c)
| TypeAbbrev t i ->
let t' = simplify_typ env t in
B.update_typ_abbrev (fst env) i t';
decl_with_v d (TypeAbbrev t' i)
| Enum t i cases ->
let t = simplify_typ env t in
decl_with_v d (Enum t i cases)
| Record tdnames params wopt fields ->
let params = List.map (fun (t, i, q) -> simplify_typ env t, i, q) params in
let fields = List.map (simplify_field env) fields in
let wopt =
match wopt with
| None -> None
| Some w -> Some (simplify_expr env w)
in
decl_with_v d (Record tdnames params wopt fields)
| CaseType tdnames params switch ->
let params = List.map (fun (t, i, q) -> simplify_typ env t, i, q) params in
let switch = simplify_switch_case env switch in
decl_with_v d (CaseType tdnames params switch)
| OutputType out_t ->
decl_with_v d
(OutputType ({ out_t with out_typ_fields = simplify_out_fields env out_t.out_typ_fields }))
| ExternType tdnames -> d
| ExternFn f ret params ->
let ret = simplify_typ env ret in
let params = List.map (fun (t, i, q) -> simplify_typ env t, i, q) params in
decl_with_v d (ExternFn f ret params)
| ExternProbe _ -> d | false |
Pulse.Checker.Bind.fst | Pulse.Checker.Bind.check_bind | val check_bind
(g:env)
(pre:term)
(pre_typing:tot_typing g pre tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(t:st_term{Tm_Bind? t.term})
(check:check_t)
: T.Tac (checker_result_t g pre post_hint) | val check_bind
(g:env)
(pre:term)
(pre_typing:tot_typing g pre tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(t:st_term{Tm_Bind? t.term})
(check:check_t)
: T.Tac (checker_result_t g pre post_hint) | let check_bind
(g:env)
(ctxt:vprop)
(ctxt_typing:tot_typing g ctxt tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(t:st_term {Tm_Bind? t.term})
(check:check_t)
: T.Tac (checker_result_t g ctxt post_hint) =
let g = Pulse.Typing.Env.push_context g "check_bind" t.range in
debug_prover g (fun _ ->
Printf.sprintf "checking bind:\n%s\n" (P.st_term_to_string t));
if None? post_hint
then fail g (Some t.range) "check_bind: post hint is not set, please add an annotation";
let Tm_Bind { binder; head=e1; body=e2 } = t.term in
if Tm_Admit? e1.term
then ( //Discard the continuation if the head is an admit
check g ctxt ctxt_typing post_hint res_ppname e1
)
else if Tm_Abs? e1.term
then (
check_bind_fn g ctxt ctxt_typing post_hint res_ppname t check
)
else (
let (| x, g1, _, (| ctxt', ctxt'_typing |), k1 |) =
let r = check g ctxt ctxt_typing None binder.binder_ppname e1 in
(* Check that the type matches the annotation, if any *)
let ty = binder.binder_ty in
begin match ty.t with
| Tm_Unknown -> ()
| _ ->
let (| ty, _, _ |) = compute_tot_term_type g ty in //elaborate it first
let (| _, _, (| _, t, _ |), _, _ |) = r in
// TODO: once we have the rename operation then we should
// ditch this check and just elaborate the bind
// let x : ty = stapp in ...
// to
// let x0 = stapp in
// let x : t = x0 in
// rename x0 x; ...
// to leverage the pure case
if not (eq_tm ty t) then
fail g (Some e1.range)
(Printf.sprintf "Type mismatch: expected %s, got %s" (P.term_to_string ty) (P.term_to_string t))
end;
r
in
let g1 = reset_context g1 g in
let d : st_typing_in_ctxt g1 ctxt' post_hint =
let ppname = mk_ppname_no_range "_bind_c" in
let r =
check g1 ctxt' ctxt'_typing post_hint ppname (open_st_term_nv e2 (binder.binder_ppname, x)) in
apply_checker_result_k #_ #_ #(Some?.v post_hint) r ppname in
let d : st_typing_in_ctxt g ctxt post_hint = k1 post_hint d in
checker_result_for_st_typing d res_ppname
) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Bind.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 127,
"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.Checker.Bind
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Base
open Pulse.Checker.Pure
open Pulse.Checker.Prover
module T = FStar.Tactics.V2
module P = Pulse.Syntax.Printer
module Metatheory = Pulse.Typing.Metatheory
module PS = Pulse.Checker.Prover.Substs
module Abs = Pulse.Checker.Abs
#push-options "--query_stats --z3rlimit_factor 4 --split_queries no"
let check_bind_fn
(g:env)
(ctxt:vprop)
(ctxt_typing:tot_typing g ctxt tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(t:st_term {Tm_Bind? t.term})
(check:check_t)
: T.Tac (checker_result_t g ctxt post_hint)
= let Tm_Bind { binder; head; body } = t.term in
match head.term with
| Tm_Abs _ -> (
let (| t, c, head_typing |) = Abs.check_abs g head check in
if not (C_Tot? c)
then fail g (Some t.range) "check_bind_fn: head is not a total abstraction";
if None? post_hint
then fail g (Some t.range) "check_bind: please annotate the postcondition";
let x = fresh g in
let b = { binder with binder_ty = comp_res c } in
let g' = push_binding g x (binder.binder_ppname) b.binder_ty in
let ctxt_typing' : tot_typing g' ctxt tm_vprop =
Metatheory.tot_typing_weakening_single ctxt_typing x b.binder_ty in
let r = check g' _ ctxt_typing' post_hint res_ppname (open_st_term_nv body (binder.binder_ppname, x)) in
let body_typing = apply_checker_result_k #_ #_ #(Some?.v post_hint) r res_ppname in
let k = Pulse.Checker.Base.continuation_elaborator_with_bind_fn ctxt_typing b head_typing (binder.binder_ppname, x) in
let d = k post_hint body_typing in
checker_result_for_st_typing d res_ppname
)
| _ -> fail g (Some t.range) "check_bind_fn: head is not an abstraction"
#pop-options | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Bind.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Abs",
"short_module": "Abs"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
g: Pulse.Typing.Env.env ->
pre: Pulse.Syntax.Base.term ->
pre_typing: Pulse.Typing.tot_typing g pre Pulse.Syntax.Base.tm_vprop ->
post_hint: Pulse.Typing.post_hint_opt g ->
res_ppname: Pulse.Syntax.Base.ppname ->
t: Pulse.Syntax.Base.st_term{Tm_Bind? (Mkst_term?.term t)} ->
check: Pulse.Checker.Base.check_t
-> FStar.Tactics.Effect.Tac (Pulse.Checker.Base.checker_result_t g pre post_hint) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.vprop",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Typing.post_hint_opt",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.st_term",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_Tm_Bind",
"Pulse.Syntax.Base.__proj__Mkst_term__item__term",
"Pulse.Checker.Base.check_t",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.uu___is_Tm_Admit",
"Pulse.Checker.Base.checker_result_t",
"Prims.bool",
"Pulse.Syntax.Base.uu___is_Tm_Abs",
"Pulse.Checker.Bind.check_bind_fn",
"Pulse.Syntax.Base.var",
"Pulse.Typing.Env.env_extends",
"FStar.Pervasives.dtuple3",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.universe_of",
"Pulse.Checker.Base.continuation_elaborator",
"FStar.Pervasives.dfst",
"Prims.Mkdtuple2",
"Pulse.Checker.Base.checker_result_inv",
"FStar.Pervasives.Native.None",
"Pulse.Typing.post_hint_t",
"Pulse.Checker.Base.checker_result_for_st_typing",
"Pulse.Typing.Combinators.st_typing_in_ctxt",
"Pulse.Checker.Base.apply_checker_result_k",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Naming.open_st_term_nv",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ppname",
"Pulse.Syntax.Base.mk_ppname_no_range",
"Prims.eq2",
"Pulse.Typing.Env.reset_context",
"Prims.unit",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Syntax.Base.term'",
"Pulse.Syntax.Base.term",
"Prims.dtuple2",
"FStar.Pervasives.Mkdtuple3",
"Prims.op_Negation",
"Pulse.Syntax.Base.eq_tm",
"Pulse.Typing.Env.fail",
"Pulse.Syntax.Base.range",
"Pulse.Syntax.Base.__proj__Mkst_term__item__range",
"Prims.string",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.term_to_string",
"Pulse.Checker.Pure.compute_tot_term_type",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Base.st_term'",
"FStar.Pervasives.Native.uu___is_None",
"Pulse.Checker.Prover.Util.debug_prover",
"Pulse.Syntax.Printer.st_term_to_string",
"Pulse.Typing.Env.push_context"
] | [] | false | true | false | false | false | let check_bind
(g: env)
(ctxt: vprop)
(ctxt_typing: tot_typing g ctxt tm_vprop)
(post_hint: post_hint_opt g)
(res_ppname: ppname)
(t: st_term{Tm_Bind? t.term})
(check: check_t)
: T.Tac (checker_result_t g ctxt post_hint) =
| let g = Pulse.Typing.Env.push_context g "check_bind" t.range in
debug_prover g (fun _ -> Printf.sprintf "checking bind:\n%s\n" (P.st_term_to_string t));
if None? post_hint
then fail g (Some t.range) "check_bind: post hint is not set, please add an annotation";
let Tm_Bind { binder = binder ; head = e1 ; body = e2 } = t.term in
if Tm_Admit? e1.term
then (check g ctxt ctxt_typing post_hint res_ppname e1)
else
if Tm_Abs? e1.term
then (check_bind_fn g ctxt ctxt_typing post_hint res_ppname t check)
else
(let (| x , g1 , _ , (| ctxt' , ctxt'_typing |) , k1 |) =
let r = check g ctxt ctxt_typing None binder.binder_ppname e1 in
let ty = binder.binder_ty in
(match ty.t with
| Tm_Unknown -> ()
| _ ->
let (| ty , _ , _ |) = compute_tot_term_type g ty in
let (| _ , _ , (| _ , t , _ |) , _ , _ |) = r in
if not (eq_tm ty t)
then
fail g
(Some e1.range)
(Printf.sprintf "Type mismatch: expected %s, got %s"
(P.term_to_string ty)
(P.term_to_string t)));
r
in
let g1 = reset_context g1 g in
let d:st_typing_in_ctxt g1 ctxt' post_hint =
let ppname = mk_ppname_no_range "_bind_c" in
let r =
check g1
ctxt'
ctxt'_typing
post_hint
ppname
(open_st_term_nv e2 (binder.binder_ppname, x))
in
apply_checker_result_k #_ #_ #(Some?.v post_hint) r ppname
in
let d:st_typing_in_ctxt g ctxt post_hint = k1 post_hint d in
checker_result_for_st_typing d res_ppname) | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.upd | val upd (#a: Type) (m: map16 a) (n: int) (v: a) : map16 a | val upd (#a: Type) (m: map16 a) (n: int) (v: a) : map16 a | let upd (#a:Type) (m:map16 a) (n:int) (v:a) : map16 a =
upd16 m n v | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 71,
"start_col": 0,
"start_line": 70
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2)
[@va_qattr]
let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4)
[@va_qattr]
let sel16 (#a:Type) (m:map16 a) (n:int) : a =
match m with (m0, m1) ->
match n < 8 with true -> sel8 m0 n | false -> sel8 m1 (n - 8)
[@va_qattr]
let upd2 (#a:Type) (m:map2 a) (n:int) (v:a) : map2 a =
match m with (m0, m1) ->
match n < 1 with true -> (v, m1) | false -> (m0, v)
[@va_qattr]
let upd4 (#a:Type) (m:map4 a) (n:int) (v:a) : map4 a =
match m with (m0, m1) ->
match n < 2 with true -> (upd2 m0 n v, m1) | false -> (m0, upd2 m1 (n - 2) v)
[@va_qattr]
let upd8 (#a:Type) (m:map8 a) (n:int) (v:a) : map8 a =
match m with (m0, m1) ->
match n < 4 with true -> (upd4 m0 n v, m1) | false -> (m0, upd4 m1 (n - 4) v)
[@va_qattr]
let upd16 (#a:Type) (m:map16 a) (n:int) (v:a) : map16 a =
match m with (m0, m1) ->
match n < 8 with true -> (upd8 m0 n v, m1) | false -> (m0, upd8 m1 (n - 8) v)
val lemma_self16 (#a:Type) (m:map16 a) (n:int) (v:a) : Lemma
(requires 0 <= n /\ n < 16)
(ensures sel16 (upd16 m n v) n == v)
val lemma_other16 (#a:Type) (m:map16 a) (n1 n2:int) (v:a) : Lemma
(requires 0 <= n1 /\ n1 < 16 /\ 0 <= n2 /\ n2 < 16 /\ n1 =!= n2)
(ensures sel16 (upd16 m n1 v) n2 == sel16 m n2)
val lemma_equal16 (#a:Type) (m1 m2:map16 a) : Lemma
(requires (forall (i:int).{:pattern (sel16 m1 i) \/ (sel16 m2 i)} 0 <= i /\ i < 16 ==> sel16 m1 i == sel16 m2 i))
(ensures m1 == m2)
//[@"uninterpreted_by_smt"]
//let map = map16
[@va_qattr "opaque_to_smt"]
let sel (#a:Type) (m:map16 a) (n:int) : a =
sel16 m n | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map16 a -> n: Prims.int -> v: a -> Vale.Lib.Map16.map16 a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map16",
"Prims.int",
"Vale.Lib.Map16.upd16"
] | [] | false | false | false | true | false | let upd (#a: Type) (m: map16 a) (n: int) (v: a) : map16 a =
| upd16 m n v | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.get | val get (#a: Type) (m: map16 a) (n: int) : a | val get (#a: Type) (m: map16 a) (n: int) : a | let get (#a:Type) (m:map16 a) (n:int) : a =
sel m n | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 9,
"end_line": 74,
"start_col": 0,
"start_line": 73
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2)
[@va_qattr]
let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4)
[@va_qattr]
let sel16 (#a:Type) (m:map16 a) (n:int) : a =
match m with (m0, m1) ->
match n < 8 with true -> sel8 m0 n | false -> sel8 m1 (n - 8)
[@va_qattr]
let upd2 (#a:Type) (m:map2 a) (n:int) (v:a) : map2 a =
match m with (m0, m1) ->
match n < 1 with true -> (v, m1) | false -> (m0, v)
[@va_qattr]
let upd4 (#a:Type) (m:map4 a) (n:int) (v:a) : map4 a =
match m with (m0, m1) ->
match n < 2 with true -> (upd2 m0 n v, m1) | false -> (m0, upd2 m1 (n - 2) v)
[@va_qattr]
let upd8 (#a:Type) (m:map8 a) (n:int) (v:a) : map8 a =
match m with (m0, m1) ->
match n < 4 with true -> (upd4 m0 n v, m1) | false -> (m0, upd4 m1 (n - 4) v)
[@va_qattr]
let upd16 (#a:Type) (m:map16 a) (n:int) (v:a) : map16 a =
match m with (m0, m1) ->
match n < 8 with true -> (upd8 m0 n v, m1) | false -> (m0, upd8 m1 (n - 8) v)
val lemma_self16 (#a:Type) (m:map16 a) (n:int) (v:a) : Lemma
(requires 0 <= n /\ n < 16)
(ensures sel16 (upd16 m n v) n == v)
val lemma_other16 (#a:Type) (m:map16 a) (n1 n2:int) (v:a) : Lemma
(requires 0 <= n1 /\ n1 < 16 /\ 0 <= n2 /\ n2 < 16 /\ n1 =!= n2)
(ensures sel16 (upd16 m n1 v) n2 == sel16 m n2)
val lemma_equal16 (#a:Type) (m1 m2:map16 a) : Lemma
(requires (forall (i:int).{:pattern (sel16 m1 i) \/ (sel16 m2 i)} 0 <= i /\ i < 16 ==> sel16 m1 i == sel16 m2 i))
(ensures m1 == m2)
//[@"uninterpreted_by_smt"]
//let map = map16
[@va_qattr "opaque_to_smt"]
let sel (#a:Type) (m:map16 a) (n:int) : a =
sel16 m n
[@va_qattr "opaque_to_smt"]
let upd (#a:Type) (m:map16 a) (n:int) (v:a) : map16 a =
upd16 m n v | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map16 a -> n: Prims.int -> a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map16",
"Prims.int",
"Vale.Lib.Map16.sel"
] | [] | false | false | false | true | false | let get (#a: Type) (m: map16 a) (n: int) : a =
| sel m n | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.eta16 | val eta16 (#a: Type) (m: map16 a) : map16 a | val eta16 (#a: Type) (m: map16 a) : map16 a | let eta16 (#a:Type) (m:map16 a) : map16 a =
let m0_3 = ((get m 0, get m 1), (get m 2, get m 3)) in
let m4_7 = ((get m 4, get m 5), (get m 6, get m 7)) in
let m8_11 = ((get m 8, get m 9), (get m 10, get m 11)) in
let m12_15 = ((get m 12, get m 13), (get m 14, get m 15)) in
((m0_3, m4_7), (m8_11, m12_15)) | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 82,
"start_col": 0,
"start_line": 77
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2)
[@va_qattr]
let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4)
[@va_qattr]
let sel16 (#a:Type) (m:map16 a) (n:int) : a =
match m with (m0, m1) ->
match n < 8 with true -> sel8 m0 n | false -> sel8 m1 (n - 8)
[@va_qattr]
let upd2 (#a:Type) (m:map2 a) (n:int) (v:a) : map2 a =
match m with (m0, m1) ->
match n < 1 with true -> (v, m1) | false -> (m0, v)
[@va_qattr]
let upd4 (#a:Type) (m:map4 a) (n:int) (v:a) : map4 a =
match m with (m0, m1) ->
match n < 2 with true -> (upd2 m0 n v, m1) | false -> (m0, upd2 m1 (n - 2) v)
[@va_qattr]
let upd8 (#a:Type) (m:map8 a) (n:int) (v:a) : map8 a =
match m with (m0, m1) ->
match n < 4 with true -> (upd4 m0 n v, m1) | false -> (m0, upd4 m1 (n - 4) v)
[@va_qattr]
let upd16 (#a:Type) (m:map16 a) (n:int) (v:a) : map16 a =
match m with (m0, m1) ->
match n < 8 with true -> (upd8 m0 n v, m1) | false -> (m0, upd8 m1 (n - 8) v)
val lemma_self16 (#a:Type) (m:map16 a) (n:int) (v:a) : Lemma
(requires 0 <= n /\ n < 16)
(ensures sel16 (upd16 m n v) n == v)
val lemma_other16 (#a:Type) (m:map16 a) (n1 n2:int) (v:a) : Lemma
(requires 0 <= n1 /\ n1 < 16 /\ 0 <= n2 /\ n2 < 16 /\ n1 =!= n2)
(ensures sel16 (upd16 m n1 v) n2 == sel16 m n2)
val lemma_equal16 (#a:Type) (m1 m2:map16 a) : Lemma
(requires (forall (i:int).{:pattern (sel16 m1 i) \/ (sel16 m2 i)} 0 <= i /\ i < 16 ==> sel16 m1 i == sel16 m2 i))
(ensures m1 == m2)
//[@"uninterpreted_by_smt"]
//let map = map16
[@va_qattr "opaque_to_smt"]
let sel (#a:Type) (m:map16 a) (n:int) : a =
sel16 m n
[@va_qattr "opaque_to_smt"]
let upd (#a:Type) (m:map16 a) (n:int) (v:a) : map16 a =
upd16 m n v
let get (#a:Type) (m:map16 a) (n:int) : a =
sel m n | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map16 a -> Vale.Lib.Map16.map16 a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map16",
"FStar.Pervasives.Native.Mktuple2",
"Vale.Lib.Map16.map8",
"Vale.Lib.Map16.map4",
"FStar.Pervasives.Native.tuple2",
"Vale.Lib.Map16.map2",
"Vale.Lib.Map16.get"
] | [] | false | false | false | true | false | let eta16 (#a: Type) (m: map16 a) : map16 a =
| let m0_3 = ((get m 0, get m 1), (get m 2, get m 3)) in
let m4_7 = ((get m 4, get m 5), (get m 6, get m 7)) in
let m8_11 = ((get m 8, get m 9), (get m 10, get m 11)) in
let m12_15 = ((get m 12, get m 13), (get m 14, get m 15)) in
((m0_3, m4_7), (m8_11, m12_15)) | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.eta | val eta (#a: Type) (m: map16 a) : map16 a | val eta (#a: Type) (m: map16 a) : map16 a | let eta (#a:Type) (m:map16 a) : map16 a =
eta16 m | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 9,
"end_line": 86,
"start_col": 0,
"start_line": 85
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2)
[@va_qattr]
let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4)
[@va_qattr]
let sel16 (#a:Type) (m:map16 a) (n:int) : a =
match m with (m0, m1) ->
match n < 8 with true -> sel8 m0 n | false -> sel8 m1 (n - 8)
[@va_qattr]
let upd2 (#a:Type) (m:map2 a) (n:int) (v:a) : map2 a =
match m with (m0, m1) ->
match n < 1 with true -> (v, m1) | false -> (m0, v)
[@va_qattr]
let upd4 (#a:Type) (m:map4 a) (n:int) (v:a) : map4 a =
match m with (m0, m1) ->
match n < 2 with true -> (upd2 m0 n v, m1) | false -> (m0, upd2 m1 (n - 2) v)
[@va_qattr]
let upd8 (#a:Type) (m:map8 a) (n:int) (v:a) : map8 a =
match m with (m0, m1) ->
match n < 4 with true -> (upd4 m0 n v, m1) | false -> (m0, upd4 m1 (n - 4) v)
[@va_qattr]
let upd16 (#a:Type) (m:map16 a) (n:int) (v:a) : map16 a =
match m with (m0, m1) ->
match n < 8 with true -> (upd8 m0 n v, m1) | false -> (m0, upd8 m1 (n - 8) v)
val lemma_self16 (#a:Type) (m:map16 a) (n:int) (v:a) : Lemma
(requires 0 <= n /\ n < 16)
(ensures sel16 (upd16 m n v) n == v)
val lemma_other16 (#a:Type) (m:map16 a) (n1 n2:int) (v:a) : Lemma
(requires 0 <= n1 /\ n1 < 16 /\ 0 <= n2 /\ n2 < 16 /\ n1 =!= n2)
(ensures sel16 (upd16 m n1 v) n2 == sel16 m n2)
val lemma_equal16 (#a:Type) (m1 m2:map16 a) : Lemma
(requires (forall (i:int).{:pattern (sel16 m1 i) \/ (sel16 m2 i)} 0 <= i /\ i < 16 ==> sel16 m1 i == sel16 m2 i))
(ensures m1 == m2)
//[@"uninterpreted_by_smt"]
//let map = map16
[@va_qattr "opaque_to_smt"]
let sel (#a:Type) (m:map16 a) (n:int) : a =
sel16 m n
[@va_qattr "opaque_to_smt"]
let upd (#a:Type) (m:map16 a) (n:int) (v:a) : map16 a =
upd16 m n v
let get (#a:Type) (m:map16 a) (n:int) : a =
sel m n
[@va_qattr]
let eta16 (#a:Type) (m:map16 a) : map16 a =
let m0_3 = ((get m 0, get m 1), (get m 2, get m 3)) in
let m4_7 = ((get m 4, get m 5), (get m 6, get m 7)) in
let m8_11 = ((get m 8, get m 9), (get m 10, get m 11)) in
let m12_15 = ((get m 12, get m 13), (get m 14, get m 15)) in
((m0_3, m4_7), (m8_11, m12_15)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map16 a -> Vale.Lib.Map16.map16 a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map16",
"Vale.Lib.Map16.eta16"
] | [] | false | false | false | true | false | let eta (#a: Type) (m: map16 a) : map16 a =
| eta16 m | false |
Hacl.Impl.Box.fst | Hacl.Impl.Box.box_detached | val box_detached:
mlen:size_t
-> c:lbuffer uint8 mlen
-> tag:lbuffer uint8 16ul
-> sk:lbuffer uint8 32ul
-> pk:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul
-> m:lbuffer uint8 mlen ->
Stack size_t
(requires fun h ->
live h c /\ live h m /\ live h sk /\ live h pk /\ live h n /\ live h tag /\
disjoint tag c /\ disjoint tag m /\ eq_or_disjoint m c /\ disjoint n m /\ disjoint n c)
(ensures fun h0 r h1 ->
modifies (loc c |+| loc tag) h0 h1 /\
(let tag_cipher = Spec.box_detached (as_seq h0 sk) (as_seq h0 pk) (as_seq h0 n) (as_seq h0 m) in
match r with
| 0ul -> Some? tag_cipher /\ (let (tag_s, cipher_s) = Some?.v tag_cipher in (as_seq h1 tag, as_seq h1 c) == (tag_s, cipher_s))
| _ -> None? tag_cipher)) | val box_detached:
mlen:size_t
-> c:lbuffer uint8 mlen
-> tag:lbuffer uint8 16ul
-> sk:lbuffer uint8 32ul
-> pk:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul
-> m:lbuffer uint8 mlen ->
Stack size_t
(requires fun h ->
live h c /\ live h m /\ live h sk /\ live h pk /\ live h n /\ live h tag /\
disjoint tag c /\ disjoint tag m /\ eq_or_disjoint m c /\ disjoint n m /\ disjoint n c)
(ensures fun h0 r h1 ->
modifies (loc c |+| loc tag) h0 h1 /\
(let tag_cipher = Spec.box_detached (as_seq h0 sk) (as_seq h0 pk) (as_seq h0 n) (as_seq h0 m) in
match r with
| 0ul -> Some? tag_cipher /\ (let (tag_s, cipher_s) = Some?.v tag_cipher in (as_seq h1 tag, as_seq h1 c) == (tag_s, cipher_s))
| _ -> None? tag_cipher)) | let box_detached mlen c tag sk pk n m =
push_frame();
let k = create 32ul (u8 0) in
let r = box_beforenm k pk sk in
let res =
if r =. size 0 then
box_detached_afternm mlen c tag k n m
else 0xfffffffful in
pop_frame ();
res | {
"file_name": "code/nacl-box/Hacl.Impl.Box.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 101,
"start_col": 0,
"start_line": 92
} | module Hacl.Impl.Box
open FStar.HyperStack.All
open FStar.HyperStack
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.SecretBox
module ST = FStar.HyperStack.ST
module Spec = Spec.Box
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0"
val box_beforenm:
k:lbuffer uint8 32ul
-> pk:lbuffer uint8 32ul
-> sk:lbuffer uint8 32ul ->
Stack size_t
(requires fun h -> live h k /\ live h pk /\ live h sk /\
disjoint k pk /\ disjoint k sk)
(ensures fun h0 r h1 -> modifies (loc k) h0 h1 /\
(let key = Spec.box_beforenm (as_seq h0 pk) (as_seq h0 sk) in
match r with
| 0ul -> Some? key /\ as_seq h1 k == Some?.v key
| _ -> None? key))
[@CInline]
let box_beforenm k pk sk =
push_frame();
let n0 = create 16ul (u8 0) in
let r = Hacl.Curve25519_51.ecdh k sk pk in
let res =
if r then (
Hacl.Salsa20.hsalsa20 k k n0;
0ul)
else
0xfffffffful in
pop_frame();
res
val box_detached_afternm:
mlen:size_t
-> c:lbuffer uint8 mlen
-> tag:lbuffer uint8 16ul
-> k:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul
-> m:lbuffer uint8 mlen ->
Stack size_t
(requires fun h ->
live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\
disjoint tag c /\ disjoint tag m /\ eq_or_disjoint m c /\ disjoint n m /\ disjoint n c)
(ensures fun h0 r h1 ->
modifies (loc c |+| loc tag) h0 h1 /\ r == 0ul /\
(as_seq h1 tag, as_seq h1 c) == Spec.box_detached_afternm (as_seq h0 k) (as_seq h0 n) (as_seq h0 m))
[@CInline]
let box_detached_afternm mlen c tag k n m =
secretbox_detached mlen c tag k n m;
0ul
#set-options "--z3rlimit 100"
val box_detached:
mlen:size_t
-> c:lbuffer uint8 mlen
-> tag:lbuffer uint8 16ul
-> sk:lbuffer uint8 32ul
-> pk:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul
-> m:lbuffer uint8 mlen ->
Stack size_t
(requires fun h ->
live h c /\ live h m /\ live h sk /\ live h pk /\ live h n /\ live h tag /\
disjoint tag c /\ disjoint tag m /\ eq_or_disjoint m c /\ disjoint n m /\ disjoint n c)
(ensures fun h0 r h1 ->
modifies (loc c |+| loc tag) h0 h1 /\
(let tag_cipher = Spec.box_detached (as_seq h0 sk) (as_seq h0 pk) (as_seq h0 n) (as_seq h0 m) in
match r with
| 0ul -> Some? tag_cipher /\ (let (tag_s, cipher_s) = Some?.v tag_cipher in (as_seq h1 tag, as_seq h1 c) == (tag_s, cipher_s))
| _ -> None? tag_cipher)) | {
"checked_file": "/",
"dependencies": [
"Spec.Box.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Salsa20.fst.checked",
"Hacl.Impl.SecretBox.fst.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Box.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Spec.Box",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SecretBox",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
mlen: Lib.IntTypes.size_t ->
c: Lib.Buffer.lbuffer Lib.IntTypes.uint8 mlen ->
tag: Lib.Buffer.lbuffer Lib.IntTypes.uint8 16ul ->
sk: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
pk: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 24ul ->
m: Lib.Buffer.lbuffer Lib.IntTypes.uint8 mlen
-> FStar.HyperStack.ST.Stack Lib.IntTypes.size_t | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.op_Equals_Dot",
"Lib.IntTypes.size",
"Hacl.Impl.Box.box_detached_afternm",
"Prims.bool",
"Hacl.Impl.Box.box_beforenm",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let box_detached mlen c tag sk pk n m =
| push_frame ();
let k = create 32ul (u8 0) in
let r = box_beforenm k pk sk in
let res = if r =. size 0 then box_detached_afternm mlen c tag k n m else 0xfffffffful in
pop_frame ();
res | false |
FStar.String.fsti | FStar.String.strlen | val strlen : s: Prims.string -> Prims.nat | let strlen s = List.length (list_of_string s) | {
"file_name": "ulib/FStar.String.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 51,
"start_col": 0,
"start_line": 51
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.String
open FStar.List.Tot
(* String is a primitive type in F*.
Most of the functions in this interface have a special status in
that they are:
1. All the total functions in this module are handled by F*'s
normalizers and can be reduced during typechecking
2. All the total functions, plus two functions in the ML effect,
have native OCaml implementations in FStar_String.ml
These functions are, however, not suitable for use in Low* code,
since many of them incur implicit allocations that must be garbage
collected.
For strings in Low*, see LowStar.String, LowStar.Literal etc.
*)
type char = FStar.Char.char
/// `list_of_string` and `string_of_list`: A pair of coercions to
/// expose and pack a string as a list of characters
val list_of_string : string -> Tot (list char)
val string_of_list : list char -> Tot string
/// A pair
val string_of_list_of_string (s:string)
: Lemma (string_of_list (list_of_string s) == s)
val list_of_string_of_list (l:list char)
: Lemma (list_of_string (string_of_list l) == l)
/// `strlen s` counts the number of utf8 values in a string | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "FStar.String.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"FStar.List.Tot.Base.length",
"FStar.String.char",
"FStar.String.list_of_string",
"Prims.nat"
] | [] | false | false | false | true | false | let strlen s =
| List.length (list_of_string s) | false |
|
FStar.String.fsti | FStar.String.length | val length : s: Prims.string -> Prims.nat | let length s = strlen s | {
"file_name": "ulib/FStar.String.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 55,
"start_col": 0,
"start_line": 55
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.String
open FStar.List.Tot
(* String is a primitive type in F*.
Most of the functions in this interface have a special status in
that they are:
1. All the total functions in this module are handled by F*'s
normalizers and can be reduced during typechecking
2. All the total functions, plus two functions in the ML effect,
have native OCaml implementations in FStar_String.ml
These functions are, however, not suitable for use in Low* code,
since many of them incur implicit allocations that must be garbage
collected.
For strings in Low*, see LowStar.String, LowStar.Literal etc.
*)
type char = FStar.Char.char
/// `list_of_string` and `string_of_list`: A pair of coercions to
/// expose and pack a string as a list of characters
val list_of_string : string -> Tot (list char)
val string_of_list : list char -> Tot string
/// A pair
val string_of_list_of_string (s:string)
: Lemma (string_of_list (list_of_string s) == s)
val list_of_string_of_list (l:list char)
: Lemma (list_of_string (string_of_list l) == l)
/// `strlen s` counts the number of utf8 values in a string
/// It is not the byte length of a string
let strlen s = List.length (list_of_string s)
/// `length`, an alias for `strlen` | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "FStar.String.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"FStar.String.strlen",
"Prims.nat"
] | [] | false | false | false | true | false | let length s =
| strlen s | false |
|
Vale.Lib.Map16.fsti | Vale.Lib.Map16.sel | val sel (#a: Type) (m: map16 a) (n: int) : a | val sel (#a: Type) (m: map16 a) (n: int) : a | let sel (#a:Type) (m:map16 a) (n:int) : a =
sel16 m n | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 67,
"start_col": 0,
"start_line": 66
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2)
[@va_qattr]
let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4)
[@va_qattr]
let sel16 (#a:Type) (m:map16 a) (n:int) : a =
match m with (m0, m1) ->
match n < 8 with true -> sel8 m0 n | false -> sel8 m1 (n - 8)
[@va_qattr]
let upd2 (#a:Type) (m:map2 a) (n:int) (v:a) : map2 a =
match m with (m0, m1) ->
match n < 1 with true -> (v, m1) | false -> (m0, v)
[@va_qattr]
let upd4 (#a:Type) (m:map4 a) (n:int) (v:a) : map4 a =
match m with (m0, m1) ->
match n < 2 with true -> (upd2 m0 n v, m1) | false -> (m0, upd2 m1 (n - 2) v)
[@va_qattr]
let upd8 (#a:Type) (m:map8 a) (n:int) (v:a) : map8 a =
match m with (m0, m1) ->
match n < 4 with true -> (upd4 m0 n v, m1) | false -> (m0, upd4 m1 (n - 4) v)
[@va_qattr]
let upd16 (#a:Type) (m:map16 a) (n:int) (v:a) : map16 a =
match m with (m0, m1) ->
match n < 8 with true -> (upd8 m0 n v, m1) | false -> (m0, upd8 m1 (n - 8) v)
val lemma_self16 (#a:Type) (m:map16 a) (n:int) (v:a) : Lemma
(requires 0 <= n /\ n < 16)
(ensures sel16 (upd16 m n v) n == v)
val lemma_other16 (#a:Type) (m:map16 a) (n1 n2:int) (v:a) : Lemma
(requires 0 <= n1 /\ n1 < 16 /\ 0 <= n2 /\ n2 < 16 /\ n1 =!= n2)
(ensures sel16 (upd16 m n1 v) n2 == sel16 m n2)
val lemma_equal16 (#a:Type) (m1 m2:map16 a) : Lemma
(requires (forall (i:int).{:pattern (sel16 m1 i) \/ (sel16 m2 i)} 0 <= i /\ i < 16 ==> sel16 m1 i == sel16 m2 i))
(ensures m1 == m2)
//[@"uninterpreted_by_smt"]
//let map = map16 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map16 a -> n: Prims.int -> a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map16",
"Prims.int",
"Vale.Lib.Map16.sel16"
] | [] | false | false | false | true | false | let sel (#a: Type) (m: map16 a) (n: int) : a =
| sel16 m n | false |
FStar.String.fsti | FStar.String.maxlen | val maxlen : s: Prims.string -> n: Prims.int -> Prims.logical | let maxlen s n = b2t (normalize_term (strlen s <= n)) \/ strlen s <= n | {
"file_name": "ulib/FStar.String.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 63,
"start_col": 0,
"start_line": 63
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.String
open FStar.List.Tot
(* String is a primitive type in F*.
Most of the functions in this interface have a special status in
that they are:
1. All the total functions in this module are handled by F*'s
normalizers and can be reduced during typechecking
2. All the total functions, plus two functions in the ML effect,
have native OCaml implementations in FStar_String.ml
These functions are, however, not suitable for use in Low* code,
since many of them incur implicit allocations that must be garbage
collected.
For strings in Low*, see LowStar.String, LowStar.Literal etc.
*)
type char = FStar.Char.char
/// `list_of_string` and `string_of_list`: A pair of coercions to
/// expose and pack a string as a list of characters
val list_of_string : string -> Tot (list char)
val string_of_list : list char -> Tot string
/// A pair
val string_of_list_of_string (s:string)
: Lemma (string_of_list (list_of_string s) == s)
val list_of_string_of_list (l:list char)
: Lemma (list_of_string (string_of_list l) == l)
/// `strlen s` counts the number of utf8 values in a string
/// It is not the byte length of a string
let strlen s = List.length (list_of_string s)
/// `length`, an alias for `strlen`
unfold
let length s = strlen s
/// `maxlen`: When applied to a literal s of less than n characters,
/// `maxlen s n` reduces to `True` before going to the SMT solver.
/// Otherwise, the left disjunct reduces partially but the right
/// disjunct remains as is, allowing to keep `strlen s <= n` in the
/// context. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "FStar.String.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> n: Prims.int -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"FStar.Pervasives.normalize_term",
"Prims.bool",
"Prims.op_LessThanOrEqual",
"FStar.String.strlen",
"Prims.logical"
] | [] | false | false | false | true | true | let maxlen s n =
| b2t (normalize_term (strlen s <= n)) \/ strlen s <= n | false |
|
FStar.String.fsti | FStar.String.string_of_char | val string_of_char (c: char) : Tot string | val string_of_char (c: char) : Tot string | let string_of_char (c:char) : Tot string = make 1 c | {
"file_name": "ulib/FStar.String.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 51,
"end_line": 70,
"start_col": 0,
"start_line": 70
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.String
open FStar.List.Tot
(* String is a primitive type in F*.
Most of the functions in this interface have a special status in
that they are:
1. All the total functions in this module are handled by F*'s
normalizers and can be reduced during typechecking
2. All the total functions, plus two functions in the ML effect,
have native OCaml implementations in FStar_String.ml
These functions are, however, not suitable for use in Low* code,
since many of them incur implicit allocations that must be garbage
collected.
For strings in Low*, see LowStar.String, LowStar.Literal etc.
*)
type char = FStar.Char.char
/// `list_of_string` and `string_of_list`: A pair of coercions to
/// expose and pack a string as a list of characters
val list_of_string : string -> Tot (list char)
val string_of_list : list char -> Tot string
/// A pair
val string_of_list_of_string (s:string)
: Lemma (string_of_list (list_of_string s) == s)
val list_of_string_of_list (l:list char)
: Lemma (list_of_string (string_of_list l) == l)
/// `strlen s` counts the number of utf8 values in a string
/// It is not the byte length of a string
let strlen s = List.length (list_of_string s)
/// `length`, an alias for `strlen`
unfold
let length s = strlen s
/// `maxlen`: When applied to a literal s of less than n characters,
/// `maxlen s n` reduces to `True` before going to the SMT solver.
/// Otherwise, the left disjunct reduces partially but the right
/// disjunct remains as is, allowing to keep `strlen s <= n` in the
/// context.
unfold
let maxlen s n = b2t (normalize_term (strlen s <= n)) \/ strlen s <= n
/// `make l c`: builds a string of length `l` with each character set
/// to `c`
val make: l:nat -> char -> Tot (s:string {length s = l}) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "FStar.String.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: FStar.String.char -> Prims.string | Prims.Tot | [
"total"
] | [] | [
"FStar.String.char",
"FStar.String.make",
"Prims.string"
] | [] | false | false | false | true | false | let string_of_char (c: char) : Tot string =
| make 1 c | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.sel2 | val sel2 (#a: Type) (m: map2 a) (n: int) : a | val sel2 (#a: Type) (m: map2 a) (n: int) : a | let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1 | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 13,
"start_col": 0,
"start_line": 11
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map2 a -> n: Prims.int -> a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map2",
"Prims.int",
"Prims.op_LessThan"
] | [] | false | false | false | true | false | let sel2 (#a: Type) (m: map2 a) (n: int) : a =
| match m with
| m0, m1 ->
match n < 1 with
| true -> m0
| false -> m1 | false |
LowStar.Printf.fst | LowStar.Printf.fragments | val fragments : Type0 | let fragments = list fragment | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 162,
"start_col": 0,
"start_line": 162
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"LowStar.Printf.fragment"
] | [] | false | false | false | true | true | let fragments =
| list fragment | false |
|
Vale.Lib.Map16.fsti | Vale.Lib.Map16.upd4 | val upd4 (#a: Type) (m: map4 a) (n: int) (v: a) : map4 a | val upd4 (#a: Type) (m: map4 a) (n: int) (v: a) : map4 a | let upd4 (#a:Type) (m:map4 a) (n:int) (v:a) : map4 a =
match m with (m0, m1) ->
match n < 2 with true -> (upd2 m0 n v, m1) | false -> (m0, upd2 m1 (n - 2) v) | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 38,
"start_col": 0,
"start_line": 36
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2)
[@va_qattr]
let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4)
[@va_qattr]
let sel16 (#a:Type) (m:map16 a) (n:int) : a =
match m with (m0, m1) ->
match n < 8 with true -> sel8 m0 n | false -> sel8 m1 (n - 8)
[@va_qattr]
let upd2 (#a:Type) (m:map2 a) (n:int) (v:a) : map2 a =
match m with (m0, m1) ->
match n < 1 with true -> (v, m1) | false -> (m0, v) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map4 a -> n: Prims.int -> v: a -> Vale.Lib.Map16.map4 a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map4",
"Prims.int",
"Vale.Lib.Map16.map2",
"Prims.op_LessThan",
"FStar.Pervasives.Native.Mktuple2",
"Vale.Lib.Map16.upd2",
"Prims.op_Subtraction"
] | [] | false | false | false | true | false | let upd4 (#a: Type) (m: map4 a) (n: int) (v: a) : map4 a =
| match m with
| m0, m1 ->
match n < 2 with
| true -> (upd2 m0 n v, m1)
| false -> (m0, upd2 m1 (n - 2) v) | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.upd16 | val upd16 (#a: Type) (m: map16 a) (n: int) (v: a) : map16 a | val upd16 (#a: Type) (m: map16 a) (n: int) (v: a) : map16 a | let upd16 (#a:Type) (m:map16 a) (n:int) (v:a) : map16 a =
match m with (m0, m1) ->
match n < 8 with true -> (upd8 m0 n v, m1) | false -> (m0, upd8 m1 (n - 8) v) | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 48,
"start_col": 0,
"start_line": 46
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2)
[@va_qattr]
let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4)
[@va_qattr]
let sel16 (#a:Type) (m:map16 a) (n:int) : a =
match m with (m0, m1) ->
match n < 8 with true -> sel8 m0 n | false -> sel8 m1 (n - 8)
[@va_qattr]
let upd2 (#a:Type) (m:map2 a) (n:int) (v:a) : map2 a =
match m with (m0, m1) ->
match n < 1 with true -> (v, m1) | false -> (m0, v)
[@va_qattr]
let upd4 (#a:Type) (m:map4 a) (n:int) (v:a) : map4 a =
match m with (m0, m1) ->
match n < 2 with true -> (upd2 m0 n v, m1) | false -> (m0, upd2 m1 (n - 2) v)
[@va_qattr]
let upd8 (#a:Type) (m:map8 a) (n:int) (v:a) : map8 a =
match m with (m0, m1) ->
match n < 4 with true -> (upd4 m0 n v, m1) | false -> (m0, upd4 m1 (n - 4) v) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map16 a -> n: Prims.int -> v: a -> Vale.Lib.Map16.map16 a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map16",
"Prims.int",
"Vale.Lib.Map16.map8",
"Prims.op_LessThan",
"FStar.Pervasives.Native.Mktuple2",
"Vale.Lib.Map16.upd8",
"Prims.op_Subtraction"
] | [] | false | false | false | true | false | let upd16 (#a: Type) (m: map16 a) (n: int) (v: a) : map16 a =
| match m with
| m0, m1 ->
match n < 8 with
| true -> (upd8 m0 n v, m1)
| false -> (m0, upd8 m1 (n - 8) v) | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.sel4 | val sel4 (#a: Type) (m: map4 a) (n: int) : a | val sel4 (#a: Type) (m: map4 a) (n: int) : a | let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2) | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 18,
"start_col": 0,
"start_line": 16
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map4 a -> n: Prims.int -> a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map4",
"Prims.int",
"Vale.Lib.Map16.map2",
"Prims.op_LessThan",
"Vale.Lib.Map16.sel2",
"Prims.op_Subtraction"
] | [] | false | false | false | true | false | let sel4 (#a: Type) (m: map4 a) (n: int) : a =
| match m with
| m0, m1 ->
match n < 2 with
| true -> sel2 m0 n
| false -> sel2 m1 (n - 2) | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.sel16 | val sel16 (#a: Type) (m: map16 a) (n: int) : a | val sel16 (#a: Type) (m: map16 a) (n: int) : a | let sel16 (#a:Type) (m:map16 a) (n:int) : a =
match m with (m0, m1) ->
match n < 8 with true -> sel8 m0 n | false -> sel8 m1 (n - 8) | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 28,
"start_col": 0,
"start_line": 26
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2)
[@va_qattr]
let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map16 a -> n: Prims.int -> a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map16",
"Prims.int",
"Vale.Lib.Map16.map8",
"Prims.op_LessThan",
"Vale.Lib.Map16.sel8",
"Prims.op_Subtraction"
] | [] | false | false | false | true | false | let sel16 (#a: Type) (m: map16 a) (n: int) : a =
| match m with
| m0, m1 ->
match n < 8 with
| true -> sel8 m0 n
| false -> sel8 m1 (n - 8) | false |
LowStar.Printf.fst | LowStar.Printf.__reduce__ | val __reduce__ : Prims.eqtype | let __reduce__ = unit | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 111,
"start_col": 0,
"start_line": 111
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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.eqtype | Prims.Tot | [
"total"
] | [] | [
"Prims.unit"
] | [] | false | false | false | true | false | let __reduce__ =
| unit | false |
|
LowStar.Printf.fst | LowStar.Printf.lmbuffer | val lmbuffer : a: Type0 ->
r: LowStar.Monotonic.Buffer.srel a ->
s: LowStar.Monotonic.Buffer.srel a ->
l: FStar.UInt32.t
-> Type0 | let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
} | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 68,
"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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s` | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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 ->
r: LowStar.Monotonic.Buffer.srel a ->
s: LowStar.Monotonic.Buffer.srel a ->
l: FStar.UInt32.t
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.eq2",
"LowStar.Monotonic.Buffer.len"
] | [] | false | false | false | true | true | let lmbuffer a r s l =
| b: LB.mbuffer a r s {LB.len b == l} | false |
|
LowStar.Printf.fst | LowStar.Printf.parse_format_string | val parse_format_string (s: string) : option fragments | val parse_format_string (s: string) : option fragments | let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s) | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 234,
"start_col": 0,
"start_line": 231
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> FStar.Pervasives.Native.option LowStar.Printf.fragments | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"LowStar.Printf.parse_format",
"FStar.String.list_of_string",
"FStar.Pervasives.Native.option",
"LowStar.Printf.fragments"
] | [] | false | false | false | true | false | let parse_format_string (s: string) : option fragments =
| parse_format (list_of_string s) | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.sel8 | val sel8 (#a: Type) (m: map8 a) (n: int) : a | val sel8 (#a: Type) (m: map8 a) (n: int) : a | let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4) | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 23,
"start_col": 0,
"start_line": 21
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map8 a -> n: Prims.int -> a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map8",
"Prims.int",
"Vale.Lib.Map16.map4",
"Prims.op_LessThan",
"Vale.Lib.Map16.sel4",
"Prims.op_Subtraction"
] | [] | false | false | false | true | false | let sel8 (#a: Type) (m: map8 a) (n: int) : a =
| match m with
| m0, m1 ->
match n < 4 with
| true -> sel4 m0 n
| false -> sel4 m1 (n - 4) | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.upd8 | val upd8 (#a: Type) (m: map8 a) (n: int) (v: a) : map8 a | val upd8 (#a: Type) (m: map8 a) (n: int) (v: a) : map8 a | let upd8 (#a:Type) (m:map8 a) (n:int) (v:a) : map8 a =
match m with (m0, m1) ->
match n < 4 with true -> (upd4 m0 n v, m1) | false -> (m0, upd4 m1 (n - 4) v) | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 43,
"start_col": 0,
"start_line": 41
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2)
[@va_qattr]
let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4)
[@va_qattr]
let sel16 (#a:Type) (m:map16 a) (n:int) : a =
match m with (m0, m1) ->
match n < 8 with true -> sel8 m0 n | false -> sel8 m1 (n - 8)
[@va_qattr]
let upd2 (#a:Type) (m:map2 a) (n:int) (v:a) : map2 a =
match m with (m0, m1) ->
match n < 1 with true -> (v, m1) | false -> (m0, v)
[@va_qattr]
let upd4 (#a:Type) (m:map4 a) (n:int) (v:a) : map4 a =
match m with (m0, m1) ->
match n < 2 with true -> (upd2 m0 n v, m1) | false -> (m0, upd2 m1 (n - 2) v) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map8 a -> n: Prims.int -> v: a -> Vale.Lib.Map16.map8 a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map8",
"Prims.int",
"Vale.Lib.Map16.map4",
"Prims.op_LessThan",
"FStar.Pervasives.Native.Mktuple2",
"Vale.Lib.Map16.upd4",
"Prims.op_Subtraction"
] | [] | false | false | false | true | false | let upd8 (#a: Type) (m: map8 a) (n: int) (v: a) : map8 a =
| match m with
| m0, m1 ->
match n < 4 with
| true -> (upd4 m0 n v, m1)
| false -> (m0, upd4 m1 (n - 4) v) | false |
FStar.String.fsti | FStar.String.concat_injective | val concat_injective (s0 s0' s1 s1': string)
: Lemma
(s0 ^ s1 == s0' ^ s1' /\ (length s0 == length s0' \/ length s1 == length s1') ==>
s0 == s0' /\ s1 == s1') | val concat_injective (s0 s0' s1 s1': string)
: Lemma
(s0 ^ s1 == s0' ^ s1' /\ (length s0 == length s0' \/ length s1 == length s1') ==>
s0 == s0' /\ s1 == s1') | let concat_injective (s0 s0':string)
(s1 s1':string)
: Lemma
(s0 ^ s1 == s0' ^ s1' /\
(length s0 == length s0' \/
length s1 == length s1') ==>
s0 == s0' /\ s1 == s1')
= list_of_concat s0 s1;
list_of_concat s0' s1';
append_injective (list_of_string s0)
(list_of_string s0')
(list_of_string s1)
(list_of_string s1');
string_of_list_of_string s0;
string_of_list_of_string s0';
string_of_list_of_string s1;
string_of_list_of_string s1' | {
"file_name": "ulib/FStar.String.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 148,
"start_col": 0,
"start_line": 132
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.String
open FStar.List.Tot
(* String is a primitive type in F*.
Most of the functions in this interface have a special status in
that they are:
1. All the total functions in this module are handled by F*'s
normalizers and can be reduced during typechecking
2. All the total functions, plus two functions in the ML effect,
have native OCaml implementations in FStar_String.ml
These functions are, however, not suitable for use in Low* code,
since many of them incur implicit allocations that must be garbage
collected.
For strings in Low*, see LowStar.String, LowStar.Literal etc.
*)
type char = FStar.Char.char
/// `list_of_string` and `string_of_list`: A pair of coercions to
/// expose and pack a string as a list of characters
val list_of_string : string -> Tot (list char)
val string_of_list : list char -> Tot string
/// A pair
val string_of_list_of_string (s:string)
: Lemma (string_of_list (list_of_string s) == s)
val list_of_string_of_list (l:list char)
: Lemma (list_of_string (string_of_list l) == l)
/// `strlen s` counts the number of utf8 values in a string
/// It is not the byte length of a string
let strlen s = List.length (list_of_string s)
/// `length`, an alias for `strlen`
unfold
let length s = strlen s
/// `maxlen`: When applied to a literal s of less than n characters,
/// `maxlen s n` reduces to `True` before going to the SMT solver.
/// Otherwise, the left disjunct reduces partially but the right
/// disjunct remains as is, allowing to keep `strlen s <= n` in the
/// context.
unfold
let maxlen s n = b2t (normalize_term (strlen s <= n)) \/ strlen s <= n
/// `make l c`: builds a string of length `l` with each character set
/// to `c`
val make: l:nat -> char -> Tot (s:string {length s = l})
/// `string_of_char`: A convenient abbreviation for `make 1 c`
let string_of_char (c:char) : Tot string = make 1 c
/// `split cs s`: splits the string by delimiters in `cs`
val split: list char -> string -> Tot (list string)
/// `concat s l` concatentates the strings in `l` delimited by `s`
val concat: string -> list string -> Tot string
/// `compare s0 s1`: lexicographic ordering on strings
val compare: string -> string -> Tot int
/// `lowercase`: transform each character to its lowercase variant
val lowercase: string -> Tot string
/// `uppercase`: transform each character to its uppercase variant
val uppercase: string -> Tot string
/// `index s n`: returns the nth character in `s`
val index: s:string -> n:nat {n < length s} -> Tot char
/// `index_of s c`:
/// The first index of `c` in `s`
/// returns -1 if the char is not found, for compatibility with C
val index_of: string -> char -> Tot int
/// `sub s i len`
/// Second argument is a length, not an index.
/// Returns a substring of length `len` beginning at `i`
val sub: s:string -> i:nat -> l:nat{i + l <= length s} -> Tot (r: string {length r = l})
/// `collect f s`: maps `f` over each character of `s`
/// from left to right, appending and flattening the result
[@@(deprecated "FStar.String.collect can be defined using list_of_string and List.collect")]
val collect: (char -> FStar.All.ML string) -> string -> FStar.All.ML string
/// `substring s i len`
/// A partial variant of `sub s i len` without bounds checks.
/// May fail with index out of bounds
val substring: string -> int -> int -> Ex string
/// `get s i`: Similar to `index` except it may fail
/// if `i` is out of bounds
val get: string -> int -> Ex char
/// Some lemmas (admitted for now as we don't have a model)
val concat_length (s1 s2: string): Lemma
(ensures length (s1 ^ s2) = length s1 + length s2)
val list_of_concat (s1 s2: string): Lemma
(ensures list_of_string (s1 ^ s2) == list_of_string s1 @ list_of_string s2)
val index_string_of_list (l:list char) (i : nat{i < List.Tot.length l}) :
Lemma (
(**) list_of_string_of_list l; // necessary to get equality between the lengths
index (string_of_list l) i == List.Tot.index l i)
let index_list_of_string (s:string) (i : nat{i < length s}) :
Lemma (List.Tot.index (list_of_string s) i == index s i) =
index_string_of_list (list_of_string s) i;
string_of_list_of_string s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "FStar.String.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s0: Prims.string -> s0': Prims.string -> s1: Prims.string -> s1': Prims.string
-> FStar.Pervasives.Lemma
(ensures
s0 ^ s1 == s0' ^ s1' /\
(FStar.String.length s0 == FStar.String.length s0' \/
FStar.String.length s1 == FStar.String.length s1') ==>
s0 == s0' /\ s1 == s1') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.string",
"FStar.String.string_of_list_of_string",
"Prims.unit",
"FStar.List.Tot.Properties.append_injective",
"FStar.String.char",
"FStar.String.list_of_string",
"FStar.String.list_of_concat",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"Prims.op_Hat",
"Prims.l_or",
"Prims.nat",
"FStar.String.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let concat_injective (s0 s0' s1 s1': string)
: Lemma
(s0 ^ s1 == s0' ^ s1' /\ (length s0 == length s0' \/ length s1 == length s1') ==>
s0 == s0' /\ s1 == s1') =
| list_of_concat s0 s1;
list_of_concat s0' s1';
append_injective (list_of_string s0) (list_of_string s0') (list_of_string s1) (list_of_string s1');
string_of_list_of_string s0;
string_of_list_of_string s0';
string_of_list_of_string s1;
string_of_list_of_string s1' | false |
LowStar.Printf.fst | LowStar.Printf.frag_t | val frag_t : Type | let frag_t = either string (a:arg & arg_t a) | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 261,
"start_col": 0,
"start_line": 261
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.either",
"Prims.string",
"Prims.dtuple2",
"LowStar.Printf.arg",
"LowStar.Printf.arg_t"
] | [] | false | false | false | true | true | let frag_t =
| either string (a: arg & arg_t a) | false |
|
LowStar.Printf.fst | LowStar.Printf.normal | val normal (#a: Type) (x: a) : a | val normal (#a: Type) (x: a) : a | let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 6,
"end_line": 330,
"start_col": 0,
"start_line": 322
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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 -> a | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.iota",
"FStar.Pervasives.zeta",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Prims.Nil",
"FStar.Pervasives.delta_only",
"FStar.Pervasives.primops",
"FStar.Pervasives.simplify"
] | [] | false | false | false | true | false | let normal (#a: Type) (x: a) : a =
| FStar.Pervasives.norm [
iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify
]
x | false |
Vale.Lib.Map16.fsti | Vale.Lib.Map16.upd2 | val upd2 (#a: Type) (m: map2 a) (n: int) (v: a) : map2 a | val upd2 (#a: Type) (m: map2 a) (n: int) (v: a) : map2 a | let upd2 (#a:Type) (m:map2 a) (n:int) (v:a) : map2 a =
match m with (m0, m1) ->
match n < 1 with true -> (v, m1) | false -> (m0, v) | {
"file_name": "vale/code/lib/collections/Vale.Lib.Map16.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 33,
"start_col": 0,
"start_line": 31
} | module Vale.Lib.Map16
open FStar.Mul
open Vale.X64.Machine_s
type map2 (a:Type) = a & a
type map4 (a:Type) = map2 a & map2 a
type map8 (a:Type) = map4 a & map4 a
type map16 (a:Type) = map8 a & map8 a
[@va_qattr]
let sel2 (#a:Type) (m:map2 a) (n:int) : a =
match m with (m0, m1) ->
match n < 1 with true -> m0 | false -> m1
[@va_qattr]
let sel4 (#a:Type) (m:map4 a) (n:int) : a =
match m with (m0, m1) ->
match n < 2 with true -> sel2 m0 n | false -> sel2 m1 (n - 2)
[@va_qattr]
let sel8 (#a:Type) (m:map8 a) (n:int) : a =
match m with (m0, m1) ->
match n < 4 with true -> sel4 m0 n | false -> sel4 m1 (n - 4)
[@va_qattr]
let sel16 (#a:Type) (m:map16 a) (n:int) : a =
match m with (m0, m1) ->
match n < 8 with true -> sel8 m0 n | false -> sel8 m1 (n - 8) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Lib.Map16.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.Lib.Map16.map2 a -> n: Prims.int -> v: a -> Vale.Lib.Map16.map2 a | Prims.Tot | [
"total"
] | [] | [
"Vale.Lib.Map16.map2",
"Prims.int",
"Prims.op_LessThan",
"FStar.Pervasives.Native.Mktuple2"
] | [] | false | false | false | true | false | let upd2 (#a: Type) (m: map2 a) (n: int) (v: a) : map2 a =
| match m with
| m0, m1 ->
match n < 1 with
| true -> (v, m1)
| false -> (m0, v) | false |
FStar.String.fsti | FStar.String.index_list_of_string | val index_list_of_string (s: string) (i: nat{i < length s})
: Lemma (List.Tot.index (list_of_string s) i == index s i) | val index_list_of_string (s: string) (i: nat{i < length s})
: Lemma (List.Tot.index (list_of_string s) i == index s i) | let index_list_of_string (s:string) (i : nat{i < length s}) :
Lemma (List.Tot.index (list_of_string s) i == index s i) =
index_string_of_list (list_of_string s) i;
string_of_list_of_string s | {
"file_name": "ulib/FStar.String.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 130,
"start_col": 0,
"start_line": 127
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.String
open FStar.List.Tot
(* String is a primitive type in F*.
Most of the functions in this interface have a special status in
that they are:
1. All the total functions in this module are handled by F*'s
normalizers and can be reduced during typechecking
2. All the total functions, plus two functions in the ML effect,
have native OCaml implementations in FStar_String.ml
These functions are, however, not suitable for use in Low* code,
since many of them incur implicit allocations that must be garbage
collected.
For strings in Low*, see LowStar.String, LowStar.Literal etc.
*)
type char = FStar.Char.char
/// `list_of_string` and `string_of_list`: A pair of coercions to
/// expose and pack a string as a list of characters
val list_of_string : string -> Tot (list char)
val string_of_list : list char -> Tot string
/// A pair
val string_of_list_of_string (s:string)
: Lemma (string_of_list (list_of_string s) == s)
val list_of_string_of_list (l:list char)
: Lemma (list_of_string (string_of_list l) == l)
/// `strlen s` counts the number of utf8 values in a string
/// It is not the byte length of a string
let strlen s = List.length (list_of_string s)
/// `length`, an alias for `strlen`
unfold
let length s = strlen s
/// `maxlen`: When applied to a literal s of less than n characters,
/// `maxlen s n` reduces to `True` before going to the SMT solver.
/// Otherwise, the left disjunct reduces partially but the right
/// disjunct remains as is, allowing to keep `strlen s <= n` in the
/// context.
unfold
let maxlen s n = b2t (normalize_term (strlen s <= n)) \/ strlen s <= n
/// `make l c`: builds a string of length `l` with each character set
/// to `c`
val make: l:nat -> char -> Tot (s:string {length s = l})
/// `string_of_char`: A convenient abbreviation for `make 1 c`
let string_of_char (c:char) : Tot string = make 1 c
/// `split cs s`: splits the string by delimiters in `cs`
val split: list char -> string -> Tot (list string)
/// `concat s l` concatentates the strings in `l` delimited by `s`
val concat: string -> list string -> Tot string
/// `compare s0 s1`: lexicographic ordering on strings
val compare: string -> string -> Tot int
/// `lowercase`: transform each character to its lowercase variant
val lowercase: string -> Tot string
/// `uppercase`: transform each character to its uppercase variant
val uppercase: string -> Tot string
/// `index s n`: returns the nth character in `s`
val index: s:string -> n:nat {n < length s} -> Tot char
/// `index_of s c`:
/// The first index of `c` in `s`
/// returns -1 if the char is not found, for compatibility with C
val index_of: string -> char -> Tot int
/// `sub s i len`
/// Second argument is a length, not an index.
/// Returns a substring of length `len` beginning at `i`
val sub: s:string -> i:nat -> l:nat{i + l <= length s} -> Tot (r: string {length r = l})
/// `collect f s`: maps `f` over each character of `s`
/// from left to right, appending and flattening the result
[@@(deprecated "FStar.String.collect can be defined using list_of_string and List.collect")]
val collect: (char -> FStar.All.ML string) -> string -> FStar.All.ML string
/// `substring s i len`
/// A partial variant of `sub s i len` without bounds checks.
/// May fail with index out of bounds
val substring: string -> int -> int -> Ex string
/// `get s i`: Similar to `index` except it may fail
/// if `i` is out of bounds
val get: string -> int -> Ex char
/// Some lemmas (admitted for now as we don't have a model)
val concat_length (s1 s2: string): Lemma
(ensures length (s1 ^ s2) = length s1 + length s2)
val list_of_concat (s1 s2: string): Lemma
(ensures list_of_string (s1 ^ s2) == list_of_string s1 @ list_of_string s2)
val index_string_of_list (l:list char) (i : nat{i < List.Tot.length l}) :
Lemma (
(**) list_of_string_of_list l; // necessary to get equality between the lengths
index (string_of_list l) i == List.Tot.index l i) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.Char.fsti.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "FStar.String.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> i: Prims.nat{i < FStar.String.length s}
-> FStar.Pervasives.Lemma
(ensures FStar.List.Tot.Base.index (FStar.String.list_of_string s) i == FStar.String.index s i) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.string",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.String.length",
"FStar.String.string_of_list_of_string",
"Prims.unit",
"FStar.String.index_string_of_list",
"FStar.String.list_of_string",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.String.char",
"FStar.List.Tot.Base.index",
"FStar.String.index",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let index_list_of_string (s: string) (i: nat{i < length s})
: Lemma (List.Tot.index (list_of_string s) i == index s i) =
| index_string_of_list (list_of_string s) i;
string_of_list_of_string s | false |
LowStar.Printf.fst | LowStar.Printf.fragment_printer | val fragment_printer : Type | let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1) | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 342,
"start_col": 0,
"start_line": 338
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"LowStar.Printf.frag_t",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Printf.live_frags",
"Prims.eq2"
] | [] | false | false | false | true | true | let fragment_printer =
| acc: list frag_t
-> Stack unit (requires fun h0 -> live_frags h0 acc) (ensures fun h0 _ h1 -> h0 == h1) | false |
|
LowStar.Printf.fst | LowStar.Printf.elim_unit_arrow | val elim_unit_arrow (#t: _) (f: (unit -> t)) : t | val elim_unit_arrow (#t: _) (f: (unit -> t)) : t | let elim_unit_arrow #t (f:unit -> t) : t = f () | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 391,
"start_col": 0,
"start_line": 391
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: (_: Prims.unit -> t) -> t | Prims.Tot | [
"total"
] | [] | [
"Prims.unit"
] | [] | false | false | false | true | false | let elim_unit_arrow #t (f: (unit -> t)) : t =
| f () | false |
LowStar.Printf.fst | LowStar.Printf.no_inst | val no_inst: #a: _ -> #b: (a -> Type) -> f: (#x: a -> b x) -> unit -> #x: a -> b x | val no_inst: #a: _ -> #b: (a -> Type) -> f: (#x: a -> b x) -> unit -> #x: a -> b x | let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 84,
"end_line": 389,
"start_col": 0,
"start_line": 389
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: b x -> _: Prims.unit -> b x | Prims.Tot | [
"total"
] | [] | [
"Prims.unit"
] | [] | false | false | false | false | false | let no_inst #a (#b: (a -> Type)) (f: (#x: a -> b x)) : unit -> #x: a -> b x =
| fun () -> f | false |
LowStar.Printf.fst | LowStar.Printf.format_string | val format_string : Type0 | let format_string = s:string{normal #bool (Some? (parse_format_string s))} | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 74,
"end_line": 445,
"start_col": 0,
"start_line": 445
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
// let test2 (f: (#a:Type -> a -> a)) : id_t 0 = test f ()
// let coerce #a (#b: (a -> Type)) ($f: (#x:a -> b x)) (t:Type{norm t == (#x:a -> b x)})
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #r:LB.srel (base_typ_as_type t)
-> #s:LB.srel (base_typ_as_type t)
-> b:lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc)
= fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__reduce__] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.b2t",
"LowStar.Printf.normal",
"Prims.bool",
"FStar.Pervasives.Native.uu___is_Some",
"LowStar.Printf.fragments",
"LowStar.Printf.parse_format_string"
] | [] | false | false | false | true | true | let format_string =
| s: string{normal #bool (Some? (parse_format_string s))} | false |
|
ZetaHashAccumulator.fst | ZetaHashAccumulator.initial_hash | val initial_hash:hash_value_t | val initial_hash:hash_value_t | let initial_hash
: hash_value_t
= Seq.create 32 0uy, 0 | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 77,
"start_col": 0,
"start_line": 75
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32}
// A hash value is a pair of a (cumulative) hash and a counter
let hash_value_t =
raw_hash_value_t &
ℕ | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ZetaHashAccumulator.hash_value_t | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.Mktuple2",
"ZetaHashAccumulator.raw_hash_value_t",
"Prims.nat",
"FStar.Seq.Base.create",
"FStar.UInt8.t",
"FStar.UInt8.__uint_to_t"
] | [] | false | false | false | true | false | let initial_hash:hash_value_t =
| Seq.create 32 0uy, 0 | false |
ZetaHashAccumulator.fst | ZetaHashAccumulator.hash_one_value | val hash_one_value (s: Seq.seq U8.t {Seq.length s <= blake2_max_input_length}) : hash_value_t | val hash_one_value (s: Seq.seq U8.t {Seq.length s <= blake2_max_input_length}) : hash_value_t | let hash_one_value (s:Seq.seq U8.t { Seq.length s ≤ blake2_max_input_length })
: hash_value_t
= blake_spec s, 1 | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 19,
"end_line": 87,
"start_col": 0,
"start_line": 85
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32}
// A hash value is a pair of a (cumulative) hash and a counter
let hash_value_t =
raw_hash_value_t &
ℕ
let initial_hash
: hash_value_t
= Seq.create 32 0uy, 0
// We just assume a spec for Blake, rather than connecting with the actual HACL code
assume
val blake_spec (d:Seq.seq U8.t { Seq.length d <= blake2_max_input_length})
: out:Seq.seq U8.t { Seq.length out == 32 } | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s:
FStar.Seq.Base.seq FStar.UInt8.t
{FStar.Seq.Base.length s <= ZetaHashAccumulator.blake2_max_input_length}
-> ZetaHashAccumulator.hash_value_t | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.UInt8.t",
"Prims.b2t",
"Pulse.Lib.BoundedIntegers.op_Less_Equals",
"Prims.int",
"Pulse.Lib.BoundedIntegers.bounded_int_int",
"FStar.Seq.Base.length",
"ZetaHashAccumulator.blake2_max_input_length",
"FStar.Pervasives.Native.Mktuple2",
"ZetaHashAccumulator.raw_hash_value_t",
"Prims.nat",
"ZetaHashAccumulator.blake_spec",
"ZetaHashAccumulator.hash_value_t"
] | [] | false | false | false | false | false | let hash_one_value (s: Seq.seq U8.t {Seq.length s <= blake2_max_input_length}) : hash_value_t =
| blake_spec s, 1 | false |
ZetaHashAccumulator.fst | ZetaHashAccumulator.ha_val_core | val ha_val_core (core: ha_core) (h: hash_value_t) : vprop | val ha_val_core (core: ha_core) (h: hash_value_t) : vprop | let ha_val_core (core:ha_core) (h:hash_value_t)
: vprop
= A.pts_to core.acc (fst h) **
(exists* (n:U32.t).
pure (U32.v n == snd h) **
pts_to core.ctr n) | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 177,
"start_col": 0,
"start_line": 172
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32}
// A hash value is a pair of a (cumulative) hash and a counter
let hash_value_t =
raw_hash_value_t &
ℕ
let initial_hash
: hash_value_t
= Seq.create 32 0uy, 0
// We just assume a spec for Blake, rather than connecting with the actual HACL code
assume
val blake_spec (d:Seq.seq U8.t { Seq.length d <= blake2_max_input_length})
: out:Seq.seq U8.t { Seq.length out == 32 }
// Hashing a single value just calls Blake and sets the counter to 1
let hash_one_value (s:Seq.seq U8.t { Seq.length s ≤ blake2_max_input_length })
: hash_value_t
= blake_spec s, 1
// Hash accumulation is by XOR
let xor_bytes (s1:bytes) (s2:bytes { Seq.length s1 == Seq.length s2 }) : bytes
= Seq.init (Seq.length s1)
(λ i → Seq.index s1 i `FStar.UInt8.logxor` Seq.index s2 i)
// A version (useful for induction) of xor_bytes that only XORs the first i bytes
// In Zeta, i is requires to be less than the length of the s1
// But, here, I "overdefine" the function, which makes it a bit easier to use
// in aggregate_raw_hashes.
// We should also try to make the version with the refinement on i work
let xor_bytes_pfx (s1:bytes)
(s2:bytes { Seq.length s1 == Seq.length s2 })
(i:ℕ)
: bytes
= let i = if i > Seq.length s1 then Seq.length s1 else i in
Seq.append
(xor_bytes (Seq.slice s1 0 i) (Seq.slice s2 0 i))
(Seq.slice s1 i (Seq.length s1))
// A lemma that says that if we XOR the first i bytes of two sequences, and then
// XOR the i-th byte, we get the same result as XORing the first (i+1) bytes
let extend_hash_value (s1 s2:bytes)
(i:ℕ)
: Lemma (requires Seq.length s1 == Seq.length s2 ∧
i < Seq.length s1)
(ensures Seq.upd (xor_bytes_pfx s1 s2 i)
i
(U8.logxor (Seq.index s1 i) (Seq.index s2 i))
`Seq.equal`
xor_bytes_pfx s1 s2 (i + 1))
= ()
// Aggregating two hashes is just XORing the two hashes and adding the counters
let aggregate_hashes (h0 h1: hash_value_t)
: hash_value_t
= xor_bytes (fst h0) (fst h1),
snd h0 + snd h1
(* END Pure Spec *)
(***************************************************************)
(* Model of HACL's blake2b *)
assume
val blake2b:
nn:SZ.t{1 ≤ SZ.v nn ∧ SZ.v nn ≤ 64}
-> output: A.array U8.t { A.length output == SZ.v nn}
-> ll: SZ.t { SZ.v ll <= blake2_max_input_length}
-> d:A.array U8.t { SZ.v ll ≤ A.length d}
-> kk: SZ.t { kk == 0sz } //We do not use blake2 in keyed mode
-> _dummy: A.array U8.t // this really should be a NULL, but krml doesn't extract Steel's null pointers yet
-> #sout:Ghost.erased (Seq.lseq U8.t 32)
-> #p:perm
-> #sd:Ghost.erased (Seq.seq U8.t) { Seq.length sd == SZ.v ll}
-> stt unit
(A.pts_to output sout ** A.pts_to d #p sd)
(λ _ → A.pts_to output (blake_spec (Seq.slice sd 0 (SZ.v ll)))
**
A.pts_to d #p sd)
(***************************************************************)
(* Pulse *)
// A buffer with the input to be hashed
let hashable_buffer = b:A.array U8.t { A.length b ≤ blake2_max_input_length }
// A buffer holding the raw hash value
let hash_value_buf = x:A.array U8.t { A.length x == 32 ∧ A.is_full_array x }
// The main data structure: ha_core
// This contains a buffer with the raw hash value
// and a mutable counter
noeq
type ha_core = {
acc: hash_value_buf;
ctr: ref U32.t;
}
// The representation predicate for ha_core ties it to a hash_value_t
// An interesting bit is that at the spec level, a hash_value_t's counter
// is just a nat. But, at the implementation level, it is a U32.t,
// and the code has to take care of potential overflow. So, at the spec
// level we connect the nat and the concrete counter, indicating that | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | core: ZetaHashAccumulator.ha_core -> h: ZetaHashAccumulator.hash_value_t -> Pulse.Lib.Core.vprop | Prims.Tot | [
"total"
] | [] | [
"ZetaHashAccumulator.ha_core",
"ZetaHashAccumulator.hash_value_t",
"Pulse.Lib.Core.op_Star_Star",
"Pulse.Lib.Array.Core.pts_to",
"FStar.UInt8.t",
"ZetaHashAccumulator.__proj__Mkha_core__item__acc",
"PulseCore.FractionalPermission.full_perm",
"FStar.Pervasives.Native.fst",
"ZetaHashAccumulator.raw_hash_value_t",
"Prims.nat",
"Pulse.Lib.Core.op_exists_Star",
"FStar.UInt32.t",
"Pulse.Lib.Core.pure",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"FStar.Pervasives.Native.snd",
"Pulse.Lib.Reference.pts_to",
"ZetaHashAccumulator.__proj__Mkha_core__item__ctr",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | true | false | let ha_val_core (core: ha_core) (h: hash_value_t) : vprop =
| A.pts_to core.acc (fst h) ** (exists* (n: U32.t). pure (U32.v n == snd h) ** pts_to core.ctr n) | false |
LowStar.Printf.fst | LowStar.Printf.printf | val printf : s:normal format_string -> normal (interpret_format_string s) | val printf : s:normal format_string -> normal (interpret_format_string s) | let printf = intro_normal_f #format_string interpret_format_string printf' | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 74,
"end_line": 482,
"start_col": 0,
"start_line": 482
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
// let test2 (f: (#a:Type -> a -> a)) : id_t 0 = test f ()
// let coerce #a (#b: (a -> Type)) ($f: (#x:a -> b x)) (t:Type{norm t == (#x:a -> b x)})
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #r:LB.srel (base_typ_as_type t)
-> #s:LB.srel (base_typ_as_type t)
-> b:lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc)
= fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowStar.Printf.normal LowStar.Printf.format_string
-> LowStar.Printf.normal (LowStar.Printf.interpret_format_string s) | Prims.Tot | [
"total"
] | [] | [
"LowStar.Printf.intro_normal_f",
"LowStar.Printf.format_string",
"LowStar.Printf.interpret_format_string",
"LowStar.Printf.printf'"
] | [] | false | false | false | false | false | let printf =
| intro_normal_f #format_string interpret_format_string printf' | false |
AllocSTwHeaps.fst | AllocSTwHeaps.heap_rel | val heap_rel : h0: FStar.Monotonic.Heap.heap -> h1: FStar.Monotonic.Heap.heap -> Prims.logical | let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 84,
"end_line": 34,
"start_col": 0,
"start_line": 33
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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 | h0: FStar.Monotonic.Heap.heap -> h1: FStar.Monotonic.Heap.heap -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.Heap.heap",
"Prims.l_Forall",
"FStar.ST.ref",
"Prims.l_imp",
"FStar.Monotonic.Heap.contains",
"FStar.Heap.trivial_preorder",
"Prims.logical"
] | [] | false | false | false | true | true | let heap_rel (h0 h1: FStar.Heap.heap) =
| forall (a: Type0) (r: ref a). FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r | false |
|
AllocSTwHeaps.fst | AllocSTwHeaps.ist_pre | val ist_pre : state: Type -> Type | let ist_pre (state:Type) = state -> Type0 | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 51,
"end_line": 51,
"start_col": 0,
"start_line": 51
} | (*
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 AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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 | state: Type -> Type | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | true | let ist_pre (state: Type) =
| state -> Type0 | false |
|
AllocSTwHeaps.fst | AllocSTwHeaps.ist_post | val ist_post : state: Type -> a: Type -> Type | let ist_post (state:Type) (a:Type) = a -> state -> Type0 | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 52,
"start_col": 0,
"start_line": 52
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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 | state: Type -> a: Type -> Type | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | true | let ist_post (state a: Type) =
| a -> state -> Type0 | false |
|
ZetaHashAccumulator.fst | ZetaHashAccumulator.xor_bytes_pfx | val xor_bytes_pfx (s1: bytes) (s2: bytes{Seq.length s1 == Seq.length s2}) (i: nat) : bytes | val xor_bytes_pfx (s1: bytes) (s2: bytes{Seq.length s1 == Seq.length s2}) (i: nat) : bytes | let xor_bytes_pfx (s1:bytes)
(s2:bytes { Seq.length s1 == Seq.length s2 })
(i:ℕ)
: bytes
= let i = if i > Seq.length s1 then Seq.length s1 else i in
Seq.append
(xor_bytes (Seq.slice s1 0 i) (Seq.slice s2 0 i))
(Seq.slice s1 i (Seq.length s1)) | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 106,
"start_col": 0,
"start_line": 99
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32}
// A hash value is a pair of a (cumulative) hash and a counter
let hash_value_t =
raw_hash_value_t &
ℕ
let initial_hash
: hash_value_t
= Seq.create 32 0uy, 0
// We just assume a spec for Blake, rather than connecting with the actual HACL code
assume
val blake_spec (d:Seq.seq U8.t { Seq.length d <= blake2_max_input_length})
: out:Seq.seq U8.t { Seq.length out == 32 }
// Hashing a single value just calls Blake and sets the counter to 1
let hash_one_value (s:Seq.seq U8.t { Seq.length s ≤ blake2_max_input_length })
: hash_value_t
= blake_spec s, 1
// Hash accumulation is by XOR
let xor_bytes (s1:bytes) (s2:bytes { Seq.length s1 == Seq.length s2 }) : bytes
= Seq.init (Seq.length s1)
(λ i → Seq.index s1 i `FStar.UInt8.logxor` Seq.index s2 i)
// A version (useful for induction) of xor_bytes that only XORs the first i bytes
// In Zeta, i is requires to be less than the length of the s1
// But, here, I "overdefine" the function, which makes it a bit easier to use
// in aggregate_raw_hashes. | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: ZetaHashAccumulator.bytes ->
s2: ZetaHashAccumulator.bytes{FStar.Seq.Base.length s1 == FStar.Seq.Base.length s2} ->
i: Prims.nat
-> ZetaHashAccumulator.bytes | Prims.Tot | [
"total"
] | [] | [
"ZetaHashAccumulator.bytes",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.UInt8.t",
"FStar.Seq.Base.append",
"ZetaHashAccumulator.xor_bytes",
"FStar.Seq.Base.slice",
"Prims.l_and",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.bool"
] | [] | false | false | false | false | false | let xor_bytes_pfx (s1: bytes) (s2: bytes{Seq.length s1 == Seq.length s2}) (i: nat) : bytes =
| let i = if i > Seq.length s1 then Seq.length s1 else i in
Seq.append (xor_bytes (Seq.slice s1 0 i) (Seq.slice s2 0 i)) (Seq.slice s1 i (Seq.length s1)) | false |
AllocSTwHeaps.fst | AllocSTwHeaps.ist_wp | val ist_wp : state: Type -> a: Type -> Type | let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state) | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 76,
"end_line": 53,
"start_col": 0,
"start_line": 53
} | (*
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 AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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 | state: Type -> a: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"AllocSTwHeaps.ist_post",
"AllocSTwHeaps.ist_pre"
] | [] | false | false | false | true | true | let ist_wp (state a: Type) =
| ist_post state a -> Tot (ist_pre state) | false |
|
AllocSTwHeaps.fst | AllocSTwHeaps.lift_div_istate | val lift_div_istate : state: Type ->
rel: FStar.Preorder.preorder state ->
a: Type ->
wp: Prims.pure_wp a ->
p: AllocSTwHeaps.ist_post state a ->
s: state
-> Prims.pure_pre | let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s) | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 103,
"end_line": 64,
"start_col": 7,
"start_line": 63
} | (*
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 AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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 |
state: Type ->
rel: FStar.Preorder.preorder state ->
a: Type ->
wp: Prims.pure_wp a ->
p: AllocSTwHeaps.ist_post state a ->
s: state
-> Prims.pure_pre | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"Prims.pure_wp",
"AllocSTwHeaps.ist_post",
"Prims.l_True",
"Prims.pure_pre"
] | [] | false | false | false | true | false | let lift_div_istate
(state: Type)
(rel: preorder state)
(a: Type)
(wp: pure_wp a)
(p: ist_post state a)
(s: state)
=
| wp (fun x -> p x s) | false |
|
LowStar.Printf.fst | LowStar.Printf.skip | val skip : s:normal format_string -> normal (interpret_format_string s) | val skip : s:normal format_string -> normal (interpret_format_string s) | let skip = intro_normal_f #format_string interpret_format_string skip' | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 496,
"start_col": 0,
"start_line": 496
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
// let test2 (f: (#a:Type -> a -> a)) : id_t 0 = test f ()
// let coerce #a (#b: (a -> Type)) ($f: (#x:a -> b x)) (t:Type{norm t == (#x:a -> b x)})
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #r:LB.srel (base_typ_as_type t)
-> #s:LB.srel (base_typ_as_type t)
-> b:lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc)
= fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> ()))
noextract inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowStar.Printf.normal LowStar.Printf.format_string
-> LowStar.Printf.normal (LowStar.Printf.interpret_format_string s) | Prims.Tot | [
"total"
] | [] | [
"LowStar.Printf.intro_normal_f",
"LowStar.Printf.format_string",
"LowStar.Printf.interpret_format_string",
"LowStar.Printf.skip'"
] | [] | false | false | false | false | false | let skip =
| intro_normal_f #format_string interpret_format_string skip' | false |
AllocSTwHeaps.fst | AllocSTwHeaps.contains | val contains : r: FStar.ST.ref a -> h: FStar.Monotonic.Heap.heap -> Prims.logical | let contains (#a:Type) (r:ref a) (h:FStar.Heap.heap) =
b2t (FStar.StrongExcludedMiddle.strong_excluded_middle (FStar.Heap.contains h r)) | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 83,
"end_line": 103,
"start_col": 0,
"start_line": 102
} | (*
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 AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *)
unfold let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s)
sub_effect DIV ~> ISTATE = lift_div_istate FStar.Heap.heap heap_rel
(*A pre- and postcondition version of this preorder-indexed state monad. *)
effect IST (a:Type)
(pre:ist_pre FStar.Heap.heap)
(post:(FStar.Heap.heap -> Tot (ist_post FStar.Heap.heap a)))
=
ISTATE a (fun p s0 -> pre s0 /\ (forall x s1 . pre s0 /\ post s0 x s1 ==> p x s1))
(* A box-like modality for witnessed stable predicates for IST. *)
let ist_witnessed (p:predicate FStar.Heap.heap{stable p heap_rel}) = witnessed heap_rel p
(* Generic effects (operations) for IST. *)
assume val ist_get : unit -> IST FStar.Heap.heap (fun s0 -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
assume val ist_put : x:FStar.Heap.heap ->
IST unit (fun s0 -> heap_rel s0 x) (fun s0 _ s1 -> s1 == x)
assume val ist_witness : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun s0 -> p s0) (fun s0 _ s1 -> s0 == s1 /\ ist_witnessed p)
assume val ist_recall : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun _ -> ist_witnessed p) (fun s0 _ s1 -> s0 == s1 /\ p s1)
(* *************************************************** *)
(* Swapping the reference and heap arguments of (FStar.Heap.contains)
to use it in point-free style in (witness) and (recall). *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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: FStar.ST.ref a -> h: FStar.Monotonic.Heap.heap -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.ST.ref",
"FStar.Monotonic.Heap.heap",
"Prims.b2t",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"FStar.Monotonic.Heap.contains",
"FStar.Heap.trivial_preorder",
"Prims.logical"
] | [] | false | false | false | true | true | let contains (#a: Type) (r: ref a) (h: FStar.Heap.heap) =
| b2t (FStar.StrongExcludedMiddle.strong_excluded_middle (FStar.Heap.contains h r)) | false |
|
Hacl.Impl.Box.fst | Hacl.Impl.Box.box_open_detached | val box_open_detached:
mlen:size_t
-> m:lbuffer uint8 mlen
-> pk:lbuffer uint8 32ul
-> sk:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul
-> c:lbuffer uint8 mlen
-> tag:lbuffer uint8 16ul ->
Stack size_t
(requires fun h ->
live h c /\ live h m /\ live h pk /\ live h sk /\ live h n /\ live h tag /\
disjoint tag c /\ eq_or_disjoint m c /\ disjoint tag m /\ disjoint m n /\ disjoint c n)
(ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\
(let msg = Spec.box_open_detached (as_seq h0 pk) (as_seq h0 sk) (as_seq h0 n) (as_seq h0 tag) (as_seq h0 c) in
match r with
| 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg
| _ -> None? msg)) | val box_open_detached:
mlen:size_t
-> m:lbuffer uint8 mlen
-> pk:lbuffer uint8 32ul
-> sk:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul
-> c:lbuffer uint8 mlen
-> tag:lbuffer uint8 16ul ->
Stack size_t
(requires fun h ->
live h c /\ live h m /\ live h pk /\ live h sk /\ live h n /\ live h tag /\
disjoint tag c /\ eq_or_disjoint m c /\ disjoint tag m /\ disjoint m n /\ disjoint c n)
(ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\
(let msg = Spec.box_open_detached (as_seq h0 pk) (as_seq h0 sk) (as_seq h0 n) (as_seq h0 tag) (as_seq h0 c) in
match r with
| 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg
| _ -> None? msg)) | let box_open_detached mlen m pk sk n c tag =
push_frame();
let k = create 32ul (u8 0) in
let r = box_beforenm k pk sk in
let res =
if r =. size 0 then
box_open_detached_afternm mlen m k n c tag
else 0xfffffffful in
pop_frame();
res | {
"file_name": "code/nacl-box/Hacl.Impl.Box.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 154,
"start_col": 0,
"start_line": 145
} | module Hacl.Impl.Box
open FStar.HyperStack.All
open FStar.HyperStack
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.SecretBox
module ST = FStar.HyperStack.ST
module Spec = Spec.Box
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0"
val box_beforenm:
k:lbuffer uint8 32ul
-> pk:lbuffer uint8 32ul
-> sk:lbuffer uint8 32ul ->
Stack size_t
(requires fun h -> live h k /\ live h pk /\ live h sk /\
disjoint k pk /\ disjoint k sk)
(ensures fun h0 r h1 -> modifies (loc k) h0 h1 /\
(let key = Spec.box_beforenm (as_seq h0 pk) (as_seq h0 sk) in
match r with
| 0ul -> Some? key /\ as_seq h1 k == Some?.v key
| _ -> None? key))
[@CInline]
let box_beforenm k pk sk =
push_frame();
let n0 = create 16ul (u8 0) in
let r = Hacl.Curve25519_51.ecdh k sk pk in
let res =
if r then (
Hacl.Salsa20.hsalsa20 k k n0;
0ul)
else
0xfffffffful in
pop_frame();
res
val box_detached_afternm:
mlen:size_t
-> c:lbuffer uint8 mlen
-> tag:lbuffer uint8 16ul
-> k:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul
-> m:lbuffer uint8 mlen ->
Stack size_t
(requires fun h ->
live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\
disjoint tag c /\ disjoint tag m /\ eq_or_disjoint m c /\ disjoint n m /\ disjoint n c)
(ensures fun h0 r h1 ->
modifies (loc c |+| loc tag) h0 h1 /\ r == 0ul /\
(as_seq h1 tag, as_seq h1 c) == Spec.box_detached_afternm (as_seq h0 k) (as_seq h0 n) (as_seq h0 m))
[@CInline]
let box_detached_afternm mlen c tag k n m =
secretbox_detached mlen c tag k n m;
0ul
#set-options "--z3rlimit 100"
val box_detached:
mlen:size_t
-> c:lbuffer uint8 mlen
-> tag:lbuffer uint8 16ul
-> sk:lbuffer uint8 32ul
-> pk:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul
-> m:lbuffer uint8 mlen ->
Stack size_t
(requires fun h ->
live h c /\ live h m /\ live h sk /\ live h pk /\ live h n /\ live h tag /\
disjoint tag c /\ disjoint tag m /\ eq_or_disjoint m c /\ disjoint n m /\ disjoint n c)
(ensures fun h0 r h1 ->
modifies (loc c |+| loc tag) h0 h1 /\
(let tag_cipher = Spec.box_detached (as_seq h0 sk) (as_seq h0 pk) (as_seq h0 n) (as_seq h0 m) in
match r with
| 0ul -> Some? tag_cipher /\ (let (tag_s, cipher_s) = Some?.v tag_cipher in (as_seq h1 tag, as_seq h1 c) == (tag_s, cipher_s))
| _ -> None? tag_cipher))
[@CInline]
let box_detached mlen c tag sk pk n m =
push_frame();
let k = create 32ul (u8 0) in
let r = box_beforenm k pk sk in
let res =
if r =. size 0 then
box_detached_afternm mlen c tag k n m
else 0xfffffffful in
pop_frame ();
res
val box_open_detached_afternm:
mlen:size_t
-> m:lbuffer uint8 mlen
-> k:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul
-> c:lbuffer uint8 mlen
-> tag:lbuffer uint8 16ul ->
Stack size_t
(requires fun h ->
live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\
disjoint tag c /\ eq_or_disjoint m c /\ disjoint tag m /\ disjoint m n /\ disjoint c n)
(ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\
(let msg = Spec.box_open_detached_afternm (as_seq h0 k) (as_seq h0 n) (as_seq h0 tag) (as_seq h0 c) in
match r with
| 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg
| _ -> None? msg))
[@CInline]
let box_open_detached_afternm mlen m k n c tag =
secretbox_open_detached mlen m k n c tag
val box_open_detached:
mlen:size_t
-> m:lbuffer uint8 mlen
-> pk:lbuffer uint8 32ul
-> sk:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul
-> c:lbuffer uint8 mlen
-> tag:lbuffer uint8 16ul ->
Stack size_t
(requires fun h ->
live h c /\ live h m /\ live h pk /\ live h sk /\ live h n /\ live h tag /\
disjoint tag c /\ eq_or_disjoint m c /\ disjoint tag m /\ disjoint m n /\ disjoint c n)
(ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\
(let msg = Spec.box_open_detached (as_seq h0 pk) (as_seq h0 sk) (as_seq h0 n) (as_seq h0 tag) (as_seq h0 c) in
match r with
| 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg
| _ -> None? msg)) | {
"checked_file": "/",
"dependencies": [
"Spec.Box.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Salsa20.fst.checked",
"Hacl.Impl.SecretBox.fst.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Box.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Spec.Box",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SecretBox",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
mlen: Lib.IntTypes.size_t ->
m: Lib.Buffer.lbuffer Lib.IntTypes.uint8 mlen ->
pk: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
sk: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 24ul ->
c: Lib.Buffer.lbuffer Lib.IntTypes.uint8 mlen ->
tag: Lib.Buffer.lbuffer Lib.IntTypes.uint8 16ul
-> FStar.HyperStack.ST.Stack Lib.IntTypes.size_t | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.op_Equals_Dot",
"Lib.IntTypes.size",
"Hacl.Impl.Box.box_open_detached_afternm",
"Prims.bool",
"Hacl.Impl.Box.box_beforenm",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let box_open_detached mlen m pk sk n c tag =
| push_frame ();
let k = create 32ul (u8 0) in
let r = box_beforenm k pk sk in
let res = if r =. size 0 then box_open_detached_afternm mlen m k n c tag else 0xfffffffful in
pop_frame ();
res | false |
ZetaHashAccumulator.fst | ZetaHashAccumulator.xor_bytes | val xor_bytes (s1: bytes) (s2: bytes{Seq.length s1 == Seq.length s2}) : bytes | val xor_bytes (s1: bytes) (s2: bytes{Seq.length s1 == Seq.length s2}) : bytes | let xor_bytes (s1:bytes) (s2:bytes { Seq.length s1 == Seq.length s2 }) : bytes
= Seq.init (Seq.length s1)
(λ i → Seq.index s1 i `FStar.UInt8.logxor` Seq.index s2 i) | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 71,
"end_line": 92,
"start_col": 0,
"start_line": 90
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32}
// A hash value is a pair of a (cumulative) hash and a counter
let hash_value_t =
raw_hash_value_t &
ℕ
let initial_hash
: hash_value_t
= Seq.create 32 0uy, 0
// We just assume a spec for Blake, rather than connecting with the actual HACL code
assume
val blake_spec (d:Seq.seq U8.t { Seq.length d <= blake2_max_input_length})
: out:Seq.seq U8.t { Seq.length out == 32 }
// Hashing a single value just calls Blake and sets the counter to 1
let hash_one_value (s:Seq.seq U8.t { Seq.length s ≤ blake2_max_input_length })
: hash_value_t
= blake_spec s, 1 | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: ZetaHashAccumulator.bytes ->
s2: ZetaHashAccumulator.bytes{FStar.Seq.Base.length s1 == FStar.Seq.Base.length s2}
-> ZetaHashAccumulator.bytes | Prims.Tot | [
"total"
] | [] | [
"ZetaHashAccumulator.bytes",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.UInt8.t",
"FStar.Seq.Base.init",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt8.logxor",
"FStar.Seq.Base.index"
] | [] | false | false | false | false | false | let xor_bytes (s1: bytes) (s2: bytes{Seq.length s1 == Seq.length s2}) : bytes =
| Seq.init (Seq.length s1) (fun i -> (Seq.index s1 i) `FStar.UInt8.logxor` (Seq.index s2 i)) | false |
LowStar.Printf.fst | LowStar.Printf.arg_t | val arg_t (a: arg) : Type u#1 | val arg_t (a: arg) : Type u#1 | let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a) | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 257,
"start_col": 0,
"start_line": 253
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: LowStar.Printf.arg -> Type | Prims.Tot | [
"total"
] | [] | [
"LowStar.Printf.arg",
"LowStar.Printf.base_typ",
"LowStar.Printf.lift",
"LowStar.Printf.base_typ_as_type",
"FStar.Pervasives.dtuple4",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.srel",
"LowStar.Printf.lmbuffer",
"FStar.Pervasives.dtuple3",
"Prims.unit"
] | [
"recursion"
] | false | false | false | true | true | let rec arg_t (a: arg) : Type u#1 =
| match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l: UInt32.t & r: _ & s: _ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a: Type0 & (a -> StTrivial unit) & a) | false |
AllocSTwHeaps.fst | AllocSTwHeaps.st_wp | val st_wp : a: Type -> Type | let st_wp (a:Type) = st_post a -> Tot st_pre | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 46,
"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 AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *)
unfold let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s)
sub_effect DIV ~> ISTATE = lift_div_istate FStar.Heap.heap heap_rel
(*A pre- and postcondition version of this preorder-indexed state monad. *)
effect IST (a:Type)
(pre:ist_pre FStar.Heap.heap)
(post:(FStar.Heap.heap -> Tot (ist_post FStar.Heap.heap a)))
=
ISTATE a (fun p s0 -> pre s0 /\ (forall x s1 . pre s0 /\ post s0 x s1 ==> p x s1))
(* A box-like modality for witnessed stable predicates for IST. *)
let ist_witnessed (p:predicate FStar.Heap.heap{stable p heap_rel}) = witnessed heap_rel p
(* Generic effects (operations) for IST. *)
assume val ist_get : unit -> IST FStar.Heap.heap (fun s0 -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
assume val ist_put : x:FStar.Heap.heap ->
IST unit (fun s0 -> heap_rel s0 x) (fun s0 _ s1 -> s1 == x)
assume val ist_witness : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun s0 -> p s0) (fun s0 _ s1 -> s0 == s1 /\ ist_witnessed p)
assume val ist_recall : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun _ -> ist_witnessed p) (fun s0 _ s1 -> s0 == s1 /\ p s1)
(* *************************************************** *)
(* Swapping the reference and heap arguments of (FStar.Heap.contains)
to use it in point-free style in (witness) and (recall). *)
let contains (#a:Type) (r:ref a) (h:FStar.Heap.heap) =
b2t (FStar.StrongExcludedMiddle.strong_excluded_middle (FStar.Heap.contains h r))
val contains_lemma : #a:Type ->
h:FStar.Heap.heap ->
r:ref a ->
Lemma (requires (contains r h))
(ensures (FStar.Heap.contains h r))
[SMTPat (contains r h)]
let contains_lemma #a h r = ()
(* Type of references that refines the standard notion of references by
witnessing that the given reference is allocated in every future heap. *)
type ref a = r:ref a{ist_witnessed (contains r)}
(* Assuming a source of freshness for references for a given heap. *)
assume val gen_ref : #a:Type ->
h:FStar.Heap.heap ->
Tot (r:ref a{r `Heap.unused_in` h})
(* Pre- and postconditions for the allocated references instance of IST. *)
let st_pre = FStar.Heap.heap -> Type0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"AllocSTwHeaps.st_post",
"AllocSTwHeaps.st_pre"
] | [] | false | false | false | true | true | let st_wp (a: Type) =
| st_post a -> Tot st_pre | false |
|
ZetaHashAccumulator.fst | ZetaHashAccumulator.blake2_max_input_length | val blake2_max_input_length : Prims.int | let blake2_max_input_length = pow2 32 - 1 - 128 | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 47,
"end_line": 59,
"start_col": 0,
"start_line": 59
} | (*
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.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.BoundedIntegers.op_Subtraction",
"Prims.int",
"Pulse.Lib.BoundedIntegers.bounded_int_int",
"Prims.pow2"
] | [] | false | false | false | true | false | let blake2_max_input_length =
| pow2 32 - 1 - 128 | false |
|
AllocSTwHeaps.fst | AllocSTwHeaps.st_post | val st_post : a: Type -> Type | let st_post (a:Type) = a -> FStar.Heap.heap -> Type0 | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 131,
"start_col": 0,
"start_line": 131
} | (*
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 AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *)
unfold let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s)
sub_effect DIV ~> ISTATE = lift_div_istate FStar.Heap.heap heap_rel
(*A pre- and postcondition version of this preorder-indexed state monad. *)
effect IST (a:Type)
(pre:ist_pre FStar.Heap.heap)
(post:(FStar.Heap.heap -> Tot (ist_post FStar.Heap.heap a)))
=
ISTATE a (fun p s0 -> pre s0 /\ (forall x s1 . pre s0 /\ post s0 x s1 ==> p x s1))
(* A box-like modality for witnessed stable predicates for IST. *)
let ist_witnessed (p:predicate FStar.Heap.heap{stable p heap_rel}) = witnessed heap_rel p
(* Generic effects (operations) for IST. *)
assume val ist_get : unit -> IST FStar.Heap.heap (fun s0 -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
assume val ist_put : x:FStar.Heap.heap ->
IST unit (fun s0 -> heap_rel s0 x) (fun s0 _ s1 -> s1 == x)
assume val ist_witness : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun s0 -> p s0) (fun s0 _ s1 -> s0 == s1 /\ ist_witnessed p)
assume val ist_recall : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun _ -> ist_witnessed p) (fun s0 _ s1 -> s0 == s1 /\ p s1)
(* *************************************************** *)
(* Swapping the reference and heap arguments of (FStar.Heap.contains)
to use it in point-free style in (witness) and (recall). *)
let contains (#a:Type) (r:ref a) (h:FStar.Heap.heap) =
b2t (FStar.StrongExcludedMiddle.strong_excluded_middle (FStar.Heap.contains h r))
val contains_lemma : #a:Type ->
h:FStar.Heap.heap ->
r:ref a ->
Lemma (requires (contains r h))
(ensures (FStar.Heap.contains h r))
[SMTPat (contains r h)]
let contains_lemma #a h r = ()
(* Type of references that refines the standard notion of references by
witnessing that the given reference is allocated in every future heap. *)
type ref a = r:ref a{ist_witnessed (contains r)}
(* Assuming a source of freshness for references for a given heap. *)
assume val gen_ref : #a:Type ->
h:FStar.Heap.heap ->
Tot (r:ref a{r `Heap.unused_in` h})
(* Pre- and postconditions for the allocated references instance of IST. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.Heap.heap"
] | [] | false | false | false | true | true | let st_post (a: Type) =
| a -> FStar.Heap.heap -> Type0 | false |
|
LowStar.Printf.fst | LowStar.Printf.base_typ_as_type | val base_typ_as_type (b: base_typ) : Type0 | val base_typ_as_type (b: base_typ) : Type0 | let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 151,
"start_col": 0,
"start_line": 139
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: LowStar.Printf.base_typ -> Type0 | Prims.Tot | [
"total"
] | [] | [
"LowStar.Printf.base_typ",
"Prims.bool",
"FStar.String.char",
"Prims.string",
"FStar.UInt8.t",
"FStar.UInt16.t",
"FStar.UInt32.t",
"FStar.UInt64.t",
"FStar.Int8.t",
"FStar.Int16.t",
"FStar.Int32.t",
"FStar.Int64.t"
] | [] | false | false | false | true | true | let base_typ_as_type (b: base_typ) : Type0 =
| match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t | false |
AllocSTwHeaps.fst | AllocSTwHeaps.st_pre | val st_pre : Type | let st_pre = FStar.Heap.heap -> Type0 | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 130,
"start_col": 0,
"start_line": 130
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *)
unfold let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s)
sub_effect DIV ~> ISTATE = lift_div_istate FStar.Heap.heap heap_rel
(*A pre- and postcondition version of this preorder-indexed state monad. *)
effect IST (a:Type)
(pre:ist_pre FStar.Heap.heap)
(post:(FStar.Heap.heap -> Tot (ist_post FStar.Heap.heap a)))
=
ISTATE a (fun p s0 -> pre s0 /\ (forall x s1 . pre s0 /\ post s0 x s1 ==> p x s1))
(* A box-like modality for witnessed stable predicates for IST. *)
let ist_witnessed (p:predicate FStar.Heap.heap{stable p heap_rel}) = witnessed heap_rel p
(* Generic effects (operations) for IST. *)
assume val ist_get : unit -> IST FStar.Heap.heap (fun s0 -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
assume val ist_put : x:FStar.Heap.heap ->
IST unit (fun s0 -> heap_rel s0 x) (fun s0 _ s1 -> s1 == x)
assume val ist_witness : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun s0 -> p s0) (fun s0 _ s1 -> s0 == s1 /\ ist_witnessed p)
assume val ist_recall : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun _ -> ist_witnessed p) (fun s0 _ s1 -> s0 == s1 /\ p s1)
(* *************************************************** *)
(* Swapping the reference and heap arguments of (FStar.Heap.contains)
to use it in point-free style in (witness) and (recall). *)
let contains (#a:Type) (r:ref a) (h:FStar.Heap.heap) =
b2t (FStar.StrongExcludedMiddle.strong_excluded_middle (FStar.Heap.contains h r))
val contains_lemma : #a:Type ->
h:FStar.Heap.heap ->
r:ref a ->
Lemma (requires (contains r h))
(ensures (FStar.Heap.contains h r))
[SMTPat (contains r h)]
let contains_lemma #a h r = ()
(* Type of references that refines the standard notion of references by
witnessing that the given reference is allocated in every future heap. *)
type ref a = r:ref a{ist_witnessed (contains r)}
(* Assuming a source of freshness for references for a given heap. *)
assume val gen_ref : #a:Type ->
h:FStar.Heap.heap ->
Tot (r:ref a{r `Heap.unused_in` h})
(* Pre- and postconditions for the allocated references instance of IST. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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 | Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.Heap.heap"
] | [] | false | false | false | true | true | let st_pre =
| FStar.Heap.heap -> Type0 | false |
|
LowStar.Printf.fst | LowStar.Printf.interpret_frags | val interpret_frags (l: fragments) (acc: list frag_t) : Type u#1 | val interpret_frags (l: fragments) (acc: list frag_t) : Type u#1 | let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc) | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 317,
"start_col": 0,
"start_line": 282
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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: LowStar.Printf.fragments -> acc: Prims.list LowStar.Printf.frag_t -> Type | Prims.Tot | [
"total"
] | [] | [
"LowStar.Printf.fragments",
"Prims.list",
"LowStar.Printf.frag_t",
"LowStar.Printf.lift",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Printf.live_frags",
"Prims.eq2",
"LowStar.Printf.base_typ",
"LowStar.Printf.fragment",
"LowStar.Printf.base_typ_as_type",
"LowStar.Printf.interpret_frags",
"Prims.Cons",
"FStar.Pervasives.Inr",
"Prims.string",
"Prims.dtuple2",
"LowStar.Printf.arg",
"LowStar.Printf.arg_t",
"Prims.Mkdtuple2",
"LowStar.Printf.Base",
"LowStar.Printf.Lift",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.srel",
"LowStar.Printf.lmbuffer",
"LowStar.Printf.Array",
"FStar.Pervasives.Mkdtuple4",
"LowStar.Printf.Any",
"FStar.Pervasives.Mkdtuple3",
"FStar.Pervasives.Inl"
] | [
"recursion"
] | false | false | false | true | true | let rec interpret_frags (l: fragments) (acc: list frag_t) : Type u#1 =
| match l with
| [] ->
lift u#0 u#1 unit
-> Stack unit (requires fun h0 -> live_frags h0 acc) (ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
x: base_typ_as_type t -> interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
l: UInt32.t ->
#r: LB.srel (base_typ_as_type t) ->
#s: LB.srel (base_typ_as_type t) ->
b: lmbuffer (base_typ_as_type t) r s l
-> interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a: Type0 -> p: (a -> StTrivial unit) -> x: a
-> interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args -> interpret_frags args (Inl s :: acc) | false |
LowStar.Printf.fst | LowStar.Printf.coerce | val coerce (x: 'a{'a == 'b}) : 'b | val coerce (x: 'a{'a == 'b}) : 'b | let coerce (x:'a{'a == 'b}) : 'b = x | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 334,
"start_col": 0,
"start_line": 334
} | (*
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 LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": 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{'a == 'b} -> 'b | Prims.Tot | [
"total"
] | [] | [
"Prims.eq2"
] | [] | false | false | false | false | false | let coerce (x: 'a{'a == 'b}) : 'b =
| x | false |
ZetaHashAccumulator.fst | ZetaHashAccumulator.aggregate_hashes | val aggregate_hashes (h0 h1: hash_value_t) : hash_value_t | val aggregate_hashes (h0 h1: hash_value_t) : hash_value_t | let aggregate_hashes (h0 h1: hash_value_t)
: hash_value_t
= xor_bytes (fst h0) (fst h1),
snd h0 + snd h1 | {
"file_name": "share/steel/examples/pulse/ZetaHashAccumulator.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 19,
"end_line": 125,
"start_col": 0,
"start_line": 122
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
* This is a port of Zeta.Steel.HashAccumulator to Pulse
*
* It models a kind of multiset hash where the the hash value is a cumulative
* XOR of an underlying hash (from Blake2b) plus a counter that records
* the number of elements that have been cumualtively hashed so far.
*
* It exercises several Pulse features, notably
* - Nested records of references and arrays
* - Folding & unfolding
* - While loops
* - Ghost functions
* - Use of F* lemmas in Pulse code
*
* It is simpler than the Steel version in various ways, as described below.
*
* Summarizing:
* - The use of erased values is significantly simpler here
* - Loops are easier and more structured
* - There are fewer rewrites and manipulations of existentials
*
* Author: N. Swamy
*)
module ZetaHashAccumulator
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module SZ = FStar.SizeT
module A = Pulse.Lib.Array
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
open Pulse.Lib.BoundedIntegers
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--fuel 0 --ifuel 0"
(**********************************************************)
(* Pure specification *)
let u32_to_u64 (x:U32.t) : U64.t = Cast.uint32_to_uint64 x
let bytes = Seq.seq U8.t
inline_for_extraction noextract
let blake2_max_input_length = pow2 32 - 1 - 128
// NOTE: we do not have an agile spec for the keyed hash functionality :(, so
// we're making Blake2-dependent assumptions without corresponding agile predicates
noextract inline_for_extraction
let hashable_bytes = s:bytes { Seq.length s ≤ blake2_max_input_length }
// The hash value is a sequence of 32 bytes
let raw_hash_value_t = Seq.lseq U8.t 32
let e_raw_hash_value_t = l:erased (Seq.seq U8.t) { Seq.length l == 32}
// A hash value is a pair of a (cumulative) hash and a counter
let hash_value_t =
raw_hash_value_t &
ℕ
let initial_hash
: hash_value_t
= Seq.create 32 0uy, 0
// We just assume a spec for Blake, rather than connecting with the actual HACL code
assume
val blake_spec (d:Seq.seq U8.t { Seq.length d <= blake2_max_input_length})
: out:Seq.seq U8.t { Seq.length out == 32 }
// Hashing a single value just calls Blake and sets the counter to 1
let hash_one_value (s:Seq.seq U8.t { Seq.length s ≤ blake2_max_input_length })
: hash_value_t
= blake_spec s, 1
// Hash accumulation is by XOR
let xor_bytes (s1:bytes) (s2:bytes { Seq.length s1 == Seq.length s2 }) : bytes
= Seq.init (Seq.length s1)
(λ i → Seq.index s1 i `FStar.UInt8.logxor` Seq.index s2 i)
// A version (useful for induction) of xor_bytes that only XORs the first i bytes
// In Zeta, i is requires to be less than the length of the s1
// But, here, I "overdefine" the function, which makes it a bit easier to use
// in aggregate_raw_hashes.
// We should also try to make the version with the refinement on i work
let xor_bytes_pfx (s1:bytes)
(s2:bytes { Seq.length s1 == Seq.length s2 })
(i:ℕ)
: bytes
= let i = if i > Seq.length s1 then Seq.length s1 else i in
Seq.append
(xor_bytes (Seq.slice s1 0 i) (Seq.slice s2 0 i))
(Seq.slice s1 i (Seq.length s1))
// A lemma that says that if we XOR the first i bytes of two sequences, and then
// XOR the i-th byte, we get the same result as XORing the first (i+1) bytes
let extend_hash_value (s1 s2:bytes)
(i:ℕ)
: Lemma (requires Seq.length s1 == Seq.length s2 ∧
i < Seq.length s1)
(ensures Seq.upd (xor_bytes_pfx s1 s2 i)
i
(U8.logxor (Seq.index s1 i) (Seq.index s2 i))
`Seq.equal`
xor_bytes_pfx s1 s2 (i + 1))
= () | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.BoundedIntegers.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "ZetaHashAccumulator.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.BoundedIntegers",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h0: ZetaHashAccumulator.hash_value_t -> h1: ZetaHashAccumulator.hash_value_t
-> ZetaHashAccumulator.hash_value_t | Prims.Tot | [
"total"
] | [] | [
"ZetaHashAccumulator.hash_value_t",
"FStar.Pervasives.Native.Mktuple2",
"ZetaHashAccumulator.raw_hash_value_t",
"Prims.nat",
"ZetaHashAccumulator.xor_bytes",
"FStar.Pervasives.Native.fst",
"Pulse.Lib.BoundedIntegers.op_Plus",
"Pulse.Lib.BoundedIntegers.bounded_int_nat",
"FStar.Pervasives.Native.snd"
] | [] | false | false | false | true | false | let aggregate_hashes (h0 h1: hash_value_t) : hash_value_t =
| xor_bytes (fst h0) (fst h1), snd h0 + snd h1 | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.